出处:/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)
如果觉得《python网络爬虫抓取图片》对你有帮助,请点赞、收藏,并留下你的观点哦!