羊了个羊通关加速多线程Python
本帖最后由 52yy1150 于 2022-9-17 19:10 编辑羊了个羊最近调整了服务器策略哦,过关接口有一点点慢,我们通过python脚本的多线程加速一下请求过程。
from multiprocessing import Pool
import requests
def get():
url = f"https://cat-match.easygame2021.com/sheep/v1/game/topic_game_over?rank_score=1&rank_state=1&rank_time=1&rank_role=1&skin=1"
headers = {
'Host': 'cat-match.easygame2021.com',
'Connection': 'keep - alive',
'charset': 'utf - 8',
't': '你爬取的token',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.28(0x18001c25) NetType/WIFI Language/en',
'content-type': 'application/json',
'Accept-Encoding': 'gzip, compress, br, deflate',
'Referer': 'https://servicewechat.com/wx141bfb9b73c970a9/16/page-frame.html'
}
response = requests.get(url, headers=headers, timeout=5)
return response.status_code
# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
# 8表示现场池容量,酌情设置
pool = Pool(8)
# range100 表示请求次数
for index in range(0, 100):
if index % 10 == 0:
print(index)
pool.apply_async(get)
pool.close()
pool.join()
z这代码怎么执行
1120996628 发表于 2022-9-17 16:05
z这代码怎么执行
安装个python就可以了
页:
[1]