码迷,mamicode.com
首页 > 其他好文 > 详细

爬取风景图

时间:2017-12-19 01:08:20      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:x86   ons   linux   def   风景   www.   tree   nbsp   print   

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

技术分享图片

 

爬取风景图

标签:x86   ons   linux   def   风景   www.   tree   nbsp   print   

原文地址:http://www.cnblogs.com/Alan-Tam/p/8058842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!