网页

image.png
效果

image.png
代码
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,i):
x=0
for imgurl in imglist:
print(imgurl)
urlretrieve(imgurl,'F:/spider/easy/%s%s.jpg' % (i,x))
x+=1
url ='https://tieba.baidu.com/p/5348945417?pn='
if __name__=='__main__':
for i in range(1,6):
setUrl=url+str(i)
print(setUrl)
html = getHtml(setUrl)
imgList = getImgList(html)
imgDownload(imgList,i)
网友评论