python基础===【爬虫】爬虫糗事百科首页图片代码
import requests import re import urllib.request def getHtml(url): page = requests.get(url) html = page.text return html def getImg(html): reg = r'src="(.+?\.jpg)" alt' imgre = re.compile(reg) imglist = re.findall(imgre,html) x = 0 for imgurl in imglist: urllib.request.urlretrieve("https:"+imgurl,'%s.jpg' % x) x+=1 html = getHtml("https://www.qiushibaike.com/imgrank/") print (getImg(html))
爬虫糗事百科首页图片代码~
纸上得来终觉浅,绝知此事要躬行!