import urllib.request
from lxml import etree
import requests
def A(a,b,c):
per=100.0*a*b/c
if per >100:
per=100
print("当前下载进度:%d"%per)
headers = {
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/63.0.3239.108 Safari/537.36"
}
m=1
i=0
while True:
url="http://www.ivsky.com/tupian/ziranfengguang/index_{}.html".format(m)
print(url)
r = requests.get(url=url, headers=headers)
html = etree.HTML(r.text)
response = html.xpath(".//img/@src")
next_page=html.xpath("//a[@class=‘page-next‘]/text()")
for img_url in response:
urllib.request.urlretrieve(img_url, "/home/zhangxi/node_modules/" + str(i) + ",jpg", A)
i += 1
if next_page:
m+=1
else:
break