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))

爬虫糗事百科首页图片代码~

posted @ 2017-10-24 08:45  AAA五金批发王建军  阅读(171)  评论(0编辑  收藏  举报