Python crawling pictures abbreviated

参考:https://blog.csdn.net/tanlangqie/article/details/79506543

# -*- coding:utf-8 -*-
import urllib
import urllib.request
import re

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

def getImg(html):
reg = 'data-original="(.+?\.jpg)"'
imgre = re.compile(reg)
imglist = re.findall(imgre, html.decode('utf-8'))
localpath='G:/photo/'
x = 1
for imgurl in imglist :
urllib.request.urlretrieve(imgurl,localpath+'%s.jpg' % x)
print('正在下载第%s张图片'% x)
x+=1
if x>20:
break
return None

html = getHtml("https://www.zhihu.com/question/27364360")
getImg(html)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324914857&siteId=291194637