Crawler/web/yutian_top/get_captcha.py

59 lines
1.7 KiB
Python

import time
import requests
import uuid
def get_session_id():
random_str = str(uuid.uuid4().hex)
return random_str
def download_captcha(i, random_str):
cookies = {
'PHPSESSID': random_str,
}
headers = {
'accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'cache-control': 'no-cache',
'pragma': 'no-cache',
'priority': 'i',
'referer': 'https://www.yutian.top/login',
'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'image',
'sec-fetch-mode': 'no-cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
}
params = {
'codeSetType': '2',
'length': '4',
'time': str(int(time.time() * 1000)),
}
if i % 2 == 0:
url = 'https://www.yutian.top/user_center/captcha/picture'
else:
url = 'https://www.fnrc.vip/user_center/captcha/picture'
response = requests.get(url, params=params, cookies=cookies,
headers=headers)
if response.status_code == 200:
file_path = f'./captcha_pic/{i}.png'
with open(file_path, 'wb') as f:
f.write(response.content)
print("验证码图片已保存为 {}".format(file_path))
i = 299
session_id = get_session_id()
while i < 600:
download_captcha(i, session_id)
if i % 20 == 0:
session_id = get_session_id()
time.sleep(0.5)
i += 1