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

爬去图片演讲

时间:2020-12-10 11:01:08      阅读:4      评论:0      收藏:0      [点我收藏+]

标签: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

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