直接动手做最靠谱!废话不多说,直接上代码,首先是Copy了一段流行的网页图片获取代码:
#coding=utf-8
import urllib
import re
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImg(html):
reg = r'src="(.+?\.jpg)"'
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
x = 1
for imgurl in imglist:
urllib.urlretrieve(imgurl,'D:\%s.jpg' % x)
x+=1
html = getHtml("https://www.zhihu.com/question/XXX")
getimage = getImg(html)
print(getimage)