0

使用Xidel,我需要提取包含通用模式的 @srcset 属性中的所有图像尺寸:“ (\d+)w

./xidel "url_with_images" -e '?'

请参阅此图像示例

<img ... @srcset="https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-696x457.jpg 696w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-220x144.jpg 220w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-300x197.jpg 300w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-768x504.jpg 768w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-475x312.jpg 475w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-741x486.jpg 741w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-640x420.jpg 640w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu.jpg 800w" />

Xidel 预期输出:

696w
220w
300w
768w
475w
741w
650w
800w
4

1 回答 1

2

http://www.benibela.de/documentation/internettools/xpath-functions.html#x-extract

如果 flags 包含 *,则返回所有匹配项。

cat <<EOF | xidel -s - -e 'extract(//@srcset,"(\d+w)",1,"*")'
<img srcset="https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-696x457.jpg 696w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-220x144.jpg 220w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-300x197.jpg 300w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-768x504.jpg 768w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-475x312.jpg 475w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-741x486.jpg 741w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu-640x420.jpg 640w, https://www.jewishpress.com/wp-content/uploads/Billionaire-Arnon-Milchan-and-PM-Benjamin-Netanyahu.jpg 800w" />
EOF

696w
220w
300w
768w
475w
741w
640w
800w

-e 'tokenize(//@srcset,",") ! substring-after(.,"jpg ")'也可以。

于 2019-03-17T18:04:31.163 回答