获取指定页面中的图片地址: curl news.baidu.com | grep -Eio ‘(http|ftp|https)://[A-Za-z0-9_./]+(.jpg|.png|.gif)’
复制代码
代码如下:
<a href=”http://news.baidu.com/iphone/img/loading_3.gif”>http://news.baidu.com/iphone/img/loading_3.gif</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5dd3a7.jpg”>http://h.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5dd3a7.jpg</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5f3db2.jpg”>http://a.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5f3db2.jpg</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f612767.jpg”>http://b.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f612767.jpg</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f625857.jpg”>http://g.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f625857.jpg</a>
……
<a href=”http://news.baidu.com/resource/img/tuiguang/news_ad_header_ipad.png”>http://news.baidu.com/resource/img/tuiguang/news_ad_header_ipad.png</a>
<a href=”http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png”>http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png</a>
<a href=”http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png”>http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5dd3a7.jpg”>http://h.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5dd3a7.jpg</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5f3db2.jpg”>http://a.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102909-62ff65f5f3db2.jpg</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f612767.jpg”>http://b.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f612767.jpg</a>
<a href=”https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f625857.jpg”>http://g.hiphotos.baidu.com/news/pic/item/https://www.oocolo.com/wp-content/uploads/2022/08/20220819102910-62ff65f625857.jpg</a>
……
<a href=”http://news.baidu.com/resource/img/tuiguang/news_ad_header_ipad.png”>http://news.baidu.com/resource/img/tuiguang/news_ad_header_ipad.png</a>
<a href=”http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png”>http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png</a>
<a href=”http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png”>http://news.baidu.com/resource/img/tuiguang/news_home_ad_dialog_ipad_news.png</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