阅读背景:

getjpg.py

来源:互联网 

getjpg.py

import re
import urllib.request

def getHtml(url):
    page=urllib.request.urlopen(url)
    html=page.read()
    return html

def getImg(html):
    reg=r'img src="(http.*?)"'
    imgre=re.compile(reg)
    imglist=re.findall(imgre,html.decode('utf-8'))
    x=0
    for imgurl in imglist:
        urllib.request.urlretrieve(imgurl,'%s.jpg'%x)
        x+=1
    return imglist
        
url="https://www.zhihu.com/question/50734809"
#html=getHtml(url)
#print(html)
#print(getImg(html))
getImg(getHtml(url))
import re
import urllib.request



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: