如何使用 Xidel 从具有 @srcset 属性的图像中提取所有 @srcset 宽度字符串?

How to extract using Xidel all @srcset width strings from an image with @srcset attribute?

使用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

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

If flags contains *, all occurrences are returned.

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 ")' 也有效。