Python3 简单实现下载某个网站轮播图片
程序员文章站
2022-09-12 23:05:02
``` import re import urllib import urllib.request headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'} ... ......
import re
import urllib
import urllib.request
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
qaq =[]
##################################################################
url = "http://www.dgtle.com"
imgName = 0
redown = urllib.request.Request(url, headers=headers)
req = urllib.request.urlopen(redown, timeout=2).read()
req = req.decode('utf-8')
html = re.compile("<img src='(.*?png)'>")
imgList = html.findall(req)
print(imgList)
##################################################################
for qaq in imgList:
qaq = str(qaq)
f = open(str(imgName) + ".jpg", 'wb')
f.write((urllib.request.urlopen(qaq)).read())
imgName += 1
f.close()