1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python网络爬虫抓取图片

python网络爬虫抓取图片

时间:2021-05-14 18:12:59

相关推荐

python网络爬虫抓取图片

出处:/longshengguoji/article/details/9946675

利用python抓取网络图片的步骤:

1.根据给定的网址获取网页源代码

2.利用正则表达式把源代码中的图片地址过滤出来

3.根据过滤出来的图片地址下载网络图片

[python]view plaincopyimportre importurllib defgetHtml(url): page=urllib.urlopen(url) html=page.read() returnhtml defgetImg(html): reg=r'src="(.+?\.jpg)"pic_ext' imgre=pile(reg) imglist=imgre.findall(html) x=0 forimgurlinimglist: urllib.urlretrieve(imgurl,'%s.jpg'%x) x=x+1 html=getHtml("/p/2460150866") getImg(html)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。