import re import urllib.request class Picture(object): def run(self): # 定义变量url 获取要下载图片的地址 url = "http://www.txt100.com/bbrvtwyhknv/85774146.html" response = urllib.request.urlopen(url).read().decode('utf-8') imglist = re.findall('src="(.+?\.jpg)"', response) x = 0 for imgurl in imglist: imgurl = 'http://www.txt100.com' + imgurl urllib.request.urlretrieve(imgurl, "./{}.jpg".format(x)) x = x + 1 print("第", x, "张下载完毕") if __name__ == '__main__': p = Picture() p.run()