您的位置:首页 > 编程语言 > Python开发

用python批量下载图片

2016-01-26 13:20 447 查看
#下载知乎上的图片
from urllib.request import urlopen
from urllib.request import urlretrieve
from bs4 import BeautifulSoup
import re

def getUrl(url):
html=urlopen(url)
bsObj=BeautifulSoup(html,"html.parser")
links=bsObj.findAll('img',src=re.compile('pic.*zhimg.com/[a-z 0-9]*_b\.(jpg|png)'))
i=0
for link in links:
i+=1
print(link.attrs['src'])
path='E:/'+str(i)+'.jpg'
urlretrieve(link.attrs['src'],path)

getUrl('https://www.zhihu.com/question/40007169#answer-29511584')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: