import re
from urllib.request import urlopen, urlretrieve
# 下载HTML
def getHtml(url):
page = urlopen(url)
html = page.read()
return html
# 从html中解析出图片URL
def getImgList(html):
reg = r'src="(https://imgsa.baidu.com/.*?\.jpg)"'
imgre = re.compile(reg)
htmld = html.decode('utf-8')
imglist = imgre.findall(htmld)
return imglist
# 下载处理
def imgDownload(imglist):
x=0
for imgurl in imglist:
print(imgurl)
urlretrieve(imgurl,'F:/spider/easy/%s.jpg' % x)
x+=1
url ='https://tieba.baidu.com/p/5348945417'
html = getHtml(url)
imgList=getImgList(html)
imgDownload(imgList)
Python爬取图片1——简单爬取图片
最新推荐文章于 2024-07-22 17:25:13 发布