爬去图片演讲

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)
上一篇:爬虫-下载指定图片


下一篇:vue - element admin 公用上传