我正在wget上编写一个网页src代码,然后使用pup获取我需要的<meta>标记。现在,我只想打印content字段的值。
在这种情况下,我想要的输出是:https://example.com/my/folder/first.jpg?foo=bar
# wget page to /tmp/output.html
IMAGE_URL=$(cat /tmp/output.html | pup 'meta[property*="og:image"]')
echo $IMAGE_URL is:
<meta property="og:image" content="https://example.com/my/folder/first.jpg?foo=bar">发布于 2021-03-27 06:06:55
wget -O /tmp/output.html --user-agent="user-agent: Whatever..." https://example.com/somewhere
IMAGE_URL=$(cat /tmp/output.html | pup --plain 'meta[property*="og:image"]' | sed -n 's/.*content=\"\([^"]*\)".*/\1/p')发布于 2022-06-09 16:13:11
您可以使用attr{content}只获取属性的内容。
wget -O /tmp/output.html --user-agent="user-agent: Whatever..." https://example.com/somewhere
IMAGE_URL=$(cat /tmp/output.html | pup 'meta[property*="og:image"] attr{content}'https://stackoverflow.com/questions/66542545
复制相似问题