Атрибут Bash + Pup только для печати

я 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">

2 ответа

Решение
      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')

Вы можете использовать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}'

Другие вопросы по тегам