标签:range XML htm index int code mat text ext
import requests
from lxml import html
# http://pic.netbian.com/uploads/allimg/180826/113958-1535254798fc1c.jpg
# http://pic.netbian.com/4kfengjing/index_3.html
# all_url = "http://pic.netbian.com/4kfengjing/index_{}.html".format(1)
url = "http://pic.netbian.com/4kfengjing/"
response = requests.request(‘get‘, url=url)
html_etree = html.etree.HTML(response.content.decode(‘gbk‘)) # type = <class ‘lxml.._etreeElement‘>
img_url = html_etree.xpath("//ul[@class=‘clearfix‘]/li/a/img/@src")
b_content = html_etree.xpath("//ul[@class=‘clearfix‘]/li/a/b/text()")
def get_response(url):
response = requests.request(‘get‘, url=url)
return response.content
for i in range(20):
img_url_true = "http://pic.netbian.com/" + img_url[i]
print(img_url_true)
content = get_response(img_url_true)
with open(‘img/{}.jpg‘.format(b_content[i]), ‘wb+‘) as f:
f.write(content)
标签:range XML htm index int code mat text ext
原文地址:https://www.cnblogs.com/FutureHolmes/p/14069482.html