Python3 简单实现下载某个网站轮播图片
程序员文章站
2022-04-18 22:09:58
``` 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()
上一篇: 简单的Vue异步组件实例Demo
下一篇: 量子点显示器火起来了:画质是不是真的强?