# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import re
import urllib.request
def getHtml(url):
page = urllib.request.urlopen(url)
html = page.read()
return html
def getImg(html):
html = html.decode('utf_8')
reg = r'src="(.*?\.jpg)" width'
imgre = re.compile(reg)
imglist = imgre.findall(html)
return imglist
html = getHtml('https://movie.douban.com/')
x = 0
for imgurl in getImg(html):
urllib.request.urlretrieve(imgurl,'%s.jpg' % x)
x += 1
print(getImg(html))
python学习之旅-爬虫
最新推荐文章于 2022-02-21 10:13:41 发布