某气壁纸爬虫,一页24张,默认爬的是动漫涩图
多线程写了,自己挂个代{过}{滤}理地址吧
还是新人,轻点,代码写得烂,还有很大的提升空间
import requests
import json
import re
import time
import sys
import random
import string
import os
from concurrent.futures import ThreadPoolExecutor
class Netbian():
def __init__(self,):
self.headers = {"Host":"pcwallpaper.zhhainiao.com",
"Connection":"keep-alive",
"Content-Length":"273",
"Accept":"application/json, text/plain, */*",
"Origin":"https://wallpaper.zhhainiao.com",
"X-Cf-Platform":"webview",
"User-Agent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36",
"X-Cf-Device-Id":"xxxx-xxx-xxx",
"Content-Type":"application/json;charset=UTF-8",
"Referer":"https://wallpaper.zhhainiao.com/3012/staticWallpaper?author_uid=0&cityid=0&device_id=67eea75e0167b7b8385e99cc3f9d33ad&disvisible_fish=0&dynamic_support=1&encrypt_support=none_encrypt&is_new_user=1&open_id=T1e141cb175f982d561696b88000f671f&os=12&player_version=111&protocol=75&resolution_support=1&theme_support=0&trayno=3012&used_days=0&wtype_support=0&client=1&tid1=7&tid2=1001&tod1=225&tod2=0&showtagsearch=1",
"Accept-Encoding":"gzip, deflate",
"Accept-Language":"zh-CN"}
self.xiongmao={'http:':'111.79.32.227:36604','https':'http://111.79.32.227:36604'}#代{过}{滤}理地址
def mkdir():
path='C:/Users/Administrator/Desktop/元气壁纸'
path=path.strip()
path=path.rstrip("\\")
isExists=os.path.exists(path)
if not isExists:
os.makedirs(path)
print(path+' 创建成功')
else:
print(path+' 目录已存在')
num=1
def get_data(self,_num=1):
Netbian.mkdir()
url='https://pcwallpaper.zhhainiao.com/wallpaper/static/list'
data={'login_info':{},'cate_id':2,'tag_id':None,'page':_num,'page_size':24,'sort_type':2,'common':{'open_id':'T1e141cb175f982d561696b88000f67f1','token':'Pl3VllpkEAoNsz9DPZXXpahGBOAgZR030XAfhEOf','device_id':'67eea75e0167b7b8385e99cc3f9dda33','player_version':111,'platform':'pc'}}#这里三个加密参数似乎可以改几个字母
opes=requests.post(url=url,data=json.dumps(data),headers=self.headers,proxies=self.xiongmao).text#json
s=json.loads(opes)
if s['resp_common']['msg']!='ok':
print('错误')
sys.exit()
for i in range(len(s['data']['list'])):
r=requests.get(s['data']['list'][i]['jpg_url'])
with open('C:/Users/Administrator/Desktop/元气壁纸/'+''.join(random.sample(string.ascii_letters + string.digits, 16))+'.jpg', 'wb') as f:
f.write(r.content)
print('第{}张下载完成!'.format(Netbian.num))
Netbian.num+=1
def main(self,_num,page):
with ThreadPoolExecutor(max_workers=3) as t:#线程数量
for x in range(_num):
t.submit(self.get_data,page+x)
if __name__ == '__main__':
_num=1#爬取多少页
page=1#第几页开始爬取
Netbian().main(_num,page)
#Netbian().get_data()
|