fix waring or bug

This commit is contained in:
岛风 2019-09-17 01:26:17 +08:00
parent 1f33c1a40f
commit 21c48473a0

View File

@ -11,12 +11,15 @@ import os
try: try:
import requests import requests
import redis import redis
except: except:
print('检测到缺少必要包!正在尝试安装!.....') print('检测到缺少必要包!正在尝试安装!.....')
os.system(r'pip install -r requirements.txt') os.system(r'pip install -r requirements.txt')
import requests import requests
import redis import redis
requests.packages.urllib3.disable_warnings()
class PixivSpider(object): class PixivSpider(object):
@ -26,7 +29,7 @@ class PixivSpider(object):
self.r = redis.Redis(host='localhost', port=6379, decode_responses=True) self.r = redis.Redis(host='localhost', port=6379, decode_responses=True)
def get_list(self, pid): def get_list(self, pid):
response = requests.get(self.ajax_url.format(pid), headers=self.headers) response = requests.get(self.ajax_url.format(pid), headers=self.headers, verify=False)
json_data = response.json() json_data = response.json()
list_temp = json_data['body'] list_temp = json_data['body']
for l in list_temp: for l in list_temp:
@ -52,7 +55,7 @@ class PixivSpider(object):
t = 0 t = 0
while t < 3: while t < 3:
try: try:
img_temp = requests.get(url, headers=self.headers, timeout=15) img_temp = requests.get(url, headers=self.headers, timeout=15, verify=False)
break break
except requests.exceptions.ConnectTimeout: except requests.exceptions.ConnectTimeout:
print("连接超时!正在重试!") print("连接超时!正在重试!")
@ -67,7 +70,7 @@ class PixivSpider(object):
'p': f'{num}', 'p': f'{num}',
'format': 'json' 'format': 'json'
} }
response = requests.get(self.top_url, params=params, headers=self.headers) response = requests.get(self.top_url, params=params, headers=self.headers, verify=False)
json_data = response.json() json_data = response.json()
self.pixiv_spider_go(json_data['contents']) self.pixiv_spider_go(json_data['contents'])