【发布时间】:2021-06-21 13:50:02
【问题描述】:
我尝试使用以下 curl/grep/seed 组合从 html url 列表中获取图像 url(wget 我失败了 403,但cUrl 正确获取源代码):
curl -K "C:\urls.txt" | "C:\GnuWin32\bin\grep.exe" -o '(http[^\s]+(jpg|png|webp)\b)' | sed 's/\?.*//' > imglinks.txt
但我收到一个错误The command "png" is either misspelled or could not be found.
正则表达式应该是正确的:https://regex101.com/r/Qk6A0Z/1/
如何改进这段代码?
编辑:我的列表中单个url的源代码可以看到运行curl https://watchbase.com/sellita
sn-p,我想从中获取图片网址的样子
<picture>
<source type="image/webp" data-srcset="https://cdn.watchbase.com/caliber/md/origin:png/sellita/sw200-1-bd.webp" srcset="https://assets.watchbase.com/img/FFFFFF-0.png" />
<img class="lazyload" data-src="https://cdn.watchbase.com/caliber/md/sellita/sw200-1-bd.png" src="https://assets.watchbase.com/img/FFFFFF-0.png" alt="Sellita caliber SW200-1"/>
</picture>
预期的输出是一个包含所有图像 url 的文件,即使是来自 data-src 和 data-srcset 的文件。
【问题讨论】:
-
你做的很不对,为什么要用
curl -K 'C:\urls.txt' | grep -o pattern?你可以简单地使用"C:\GnuWin32\bin\grep.exe" -oP "http[^?\s]+(jpg|png|webp)\b" "C:\urls.txt" > imglinks.txt -
这样我只得到空文件imglinks.txt。如果我使用单个 url 而不是文件列表,例如
"C:\GnuWin32\bin\grep.exe" -oP "http[^?\s]+(jpg|png|webp)\b" https://watchbase.com/sellita > imglinks.txt我得到no such file or directory -
您能否显示您的
curl命令的输出并显示您预期的最终输出。 -
刚刚试过,
"C:\GnuWin32\bin\grep.exe" -oE "http[^?[:space:]]+(jpg|png|webp)\b" "C:\urls.txt"效果很好。同"C:\GnuWin32\bin\grep.exe" -oP "http[^?\s]+(jpg|png|webp)\b" "C:\urls.txt" -
无论如何,
'png' is not recognized as an internal or external command, operable program or batch file问题是由于使用了单引号引起的。使用双倍。
标签: regex windows curl sed grep