首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bash + Pup只打印属性

Bash + Pup只打印属性
EN

Stack Overflow用户
提问于 2021-03-09 07:30:07
回答 2查看 120关注 0票数 1

我正在wget上编写一个网页src代码,然后使用pup获取我需要的<meta>标记。现在,我只想打印content字段的值。

在这种情况下,我想要的输出是:https://example.com/my/folder/first.jpg?foo=bar

代码语言:javascript
复制
# 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">
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-27 06:06:55

代码语言:javascript
复制
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')
票数 0
EN

Stack Overflow用户

发布于 2022-06-09 16:13:11

您可以使用attr{content}只获取属性的内容。

代码语言:javascript
复制
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}'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66542545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档