import reimport 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()
原文地址:https://www.cnblogs.com/victorstudy/p/11237287.html
时间: 2024-10-13 08:39:49