【问题标题】:Bash + Pup printing only attributeBash + Pup 仅打印属性
【发布时间】:2021-03-09 07:30:07
【问题描述】:

我正在wgeting 网页源代码,然后使用 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">

【问题讨论】:

    标签: bash pup


    【解决方案1】:
    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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-23
      • 2016-09-03
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多