合并拉取请求#2来自nyaasuki/dev

Dev
This commit is contained in:
nyaasuki 2021-05-17 18:56:30 +08:00 committed by GitHub
commit a1e2b7f368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 20 deletions

1
.gitignore vendored
View File

@ -140,3 +140,4 @@ test.py
.DS_Store
.idea/.name
.idea/workspace.xml
.vscode/settings.json

103
Pixiv.py
View File

@ -1,12 +1,21 @@
"""
P站小爬虫 爬每日排行榜
环境需求Python3.6+ / Redis
环境需求Python3.6+ / Redis
项目地址https://github.com/nyaasuki/PixivSpider
支持 M1 芯片
"""
"""
--------------------------------------------------------------
"""
import re
import os
from cmd import Cmd
try:
import requests
@ -22,7 +31,15 @@ requests.packages.urllib3.disable_warnings()
error_list = []
class PixivSpider(object):
"""
V 1 . 0
---------------------------------------------------------------------
"""
class PixivSpider(Cmd):
def __init__(self):
self.ajax_url = 'https://www.pixiv.net/ajax/illust/{}/pages' # id
@ -108,21 +125,7 @@ class PixivSpider(object):
cls.data = data
@classmethod
def pixiv_main(cls):
cookie = pixiv.r.get('cookie')
if not cookie:
cookie = input('请输入一个cookie')
pixiv.r.set('cookie', cookie)
cls.headers = {
'accept': 'application/json',
'accept-language': 'zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6',
'dnt': '1',
'cookie': f'{cookie}',
'referer': 'https://www.pixiv.net/',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36'
}
def pixiv_main(cls):
print('开始抓取...')
for i in range(1, 11, 1): # p站每日排行榜最多为500个
pixiv.get_top_url(i)
@ -132,10 +135,74 @@ class PixivSpider(object):
error_list.append(k)
for k in error_list:
pixiv.r.delete(k)
"""
C M D
---------------------------------------------------------------------------------
"""
def main(self):
cookie = pixiv.r.get('cookie')
if not cookie:
cookie = input('[Pixiv] 请输入一个cookie')
pixiv.r.set('cookie', cookie)
self.headers = {
'accept': 'application/json',
'accept-language': 'zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6',
'dnt': '1',
'cookie': f'{cookie}',
'referer': 'https://www.pixiv.net/',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36'
}
if cookie == () :
print('[Redis] 未输入cookie部分功能受限')
else
print(f'[Redis] 成功储存Cookie{cookie}')
self.cmdloop()
def do_help(self):
print('[Help] rank - 爬取 Pixiv每日排行榜前500的插画')
print('[Help] stars - 爬取 你已经添加❤的插画 *需要用户cookie*')
print('[Help] like - 爬取 每日推荐插画 *需要用户cookie*')
print('[Help] cookie - 更换已保存的cookie')
print('[Help] quit - 退出程序')
def do_quit(self):
exit()
def do_rank(self):
self.pixiv_main()
def do_stars(self):
pass
def do_like(self):
pass
def do_cookie(self):
pass
"""
----------------------------------------------------------
"""
if __name__ == '__main__':
pixiv = PixivSpider()
pixiv.pixiv_main()
pixiv.main()
# for id_url in pixiv.get_list():
# pixiv.get_img(id_url)

View File

@ -44,7 +44,11 @@ ERROR: No matching distribution found for resquests`
此项储存在本地redis中
3.复位程序
请清除Redis中的数据更换cookie同理
## 特别提醒
正常来说,当没有出现上方问题时,程序出现问题大多为你的上网方式不够科学
缓慢更新中...
缓慢更新中...

View File

@ -1,2 +1,2 @@
redis==3.5.3
requests==2.22.0
requests==2.25.1