ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Python之多进程根据p站画师id爬取

2019-09-23 19:02:27  阅读:158  来源: 互联网

标签:__ get Python jpg 爬取 url import id


Python之p站根据id爬取图片(多进程)

import requests
import os
import time
import re
from multiprocessing import Process
from concurrent.futures import ProcessPoolExecutor
def test(id_p):
#####游览器内核需要自行添加,cookie也需要自己找,然后替换
    head = {
        'Referer': 'https://www.pixiv.net/',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
        'cookie': 'PHPSESSID=43437028_7c06ec1fd0e152e26fa0dab9c9fa919e'
    }

    headss = {
        'Referer': 'https://www.pixiv.net',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'
    }
    while True:
        if id_p != '':
            su = 0
            zp = 'https://www.pixiv.net/ajax/user/' + id_p + '/profile/all'

            ####os创建文件夹
            if not os.path.exists(f'H:\图片\P站\作者id:{id_p}'):
                os.mkdir(f'H:\图片\P站\作者id:{id_p}')
            res = requests.get(zp, headers=head)
            date = res.json()
            # 生成图片路径
            url_jpg = []
            for k in date.get('body').get('illusts').keys():
                url_jpg.append('https://www.pixiv.net/member_illust.php?mode=medium&illust_id=' + k)
            # print(url_jpg)
            for i in url_jpg:
                res_id = requests.get(i, headers=head)
                date_id = res_id.text
                url = ''.join(re.findall('"original":"(.*?)"', date_id))
                url = url.replace('\\', '')
                rese = requests.get(url, headers=headss)
                with open(f'H:\图片\P站\作者id:{id_p}\{url.split("/")[-1]}', 'wb') as fw:
                    fw.write(rese.content)
                    fw.flush()
                print(f'\r--------{id_p}--------------{url.split("/")[-1]}------{su + 1}----------------',end='')
                if i == url_jpg[-1]:
                    print('\n')
                su += 1

                time.sleep(0.2)
            time.sleep(0.5)
            print(f'-----------{id_p}作品获取完成----------')
            break



if __name__ == '__main__':
    while True:
        p_id = input('输入作者id生成网址')
        pool = ProcessPoolExecutor(3)
        p = Process(target=test,args=(p_id,))
        p.start()

标签:__,get,Python,jpg,爬取,url,import,id
来源: https://www.cnblogs.com/ledgua/p/11574060.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有