本篇内容介绍了“Linux命令行中怎么采集指定页面的图片地址及图片下载”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
获取指定页面中的图片地址: curl news.baidu.com | grep -Eio '(http|ftp|https)://[A-Za-z0-9_./]+(.jpg|.png|.gif)'
代码如下:
<a href="https://file.lsjlt.com/upload/202306/12/qbufqckbazu.jpg">https://file.lsjlt.com/upload/202306/12/qbufqckbazu.jpg</a>
<a href="https://file.lsjlt.com/upload/202306/12/3tyhr2b00bk.jpg">https://file.lsjlt.com/upload/202306/12/3tyhr2b00bk.jpg</a>
<a href="https://file.lsjlt.com/upload/202306/12/kajjbxqms40.jpg">https://file.lsjlt.com/upload/202306/12/bpg3hxlzflp.jpg</a>
<a href="https://file.lsjlt.com/upload/202306/12/4dwnf53d5ug.jpg">https://file.lsjlt.com/upload/202306/12/umh1epwr0yd.jpg</a>
<a href="https://file.lsjlt.com/upload/202306/12/02tbm3pl44f.jpg">https://file.lsjlt.com/upload/202306/12/qzdomxubpbq.jpg</a>
......
<a href="https://file.lsjlt.com/upload/202306/12/0kugpq3hcjw.jpg">https://file.lsjlt.com/upload/202306/12/0kugpq3hcjw.jpg</a>
<a href="https://file.lsjlt.com/upload/202306/12/4n0dxtjdmjs.jpg">https://file.lsjlt.com/upload/202306/12/4n0dxtjdmjs.jpg</a>
<a href="https://file.lsjlt.com/upload/202306/12/4n0dxtjdmjs.jpg">https://file.lsjlt.com/upload/202306/12/4n0dxtjdmjs.jpg</a>
grep –E 使用正则表达式
grep –i 不区分大小写
grep –o 只显示匹配的字符串
下载指定页面的图片文件:
代码如下:
curl -s news.baidu.com | grep -Eoi '(http|https|ftp)://[a-z0-9./_]*(jpg|png|gif)' | sort | uniq > url.txt && wget -q -nc -i url.txt
“Linux命令行中怎么采集指定页面的图片地址及图片下载”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!