feat: 添加 fetch_proxies3 方法以增强代理获取功能并更新相关调用
This commit is contained in:
parent
3260372edc
commit
af3945dbec
27
main.py
27
main.py
@ -170,20 +170,21 @@ def post_with_retry(url, json_payload=None, data=None, headers=None, proxies=Non
|
||||
|
||||
def gettoken():
|
||||
headers = {
|
||||
'host': 'graphql.api.dailymotion.com',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0',
|
||||
'sec-ch-ua': '"Chromium";v="136", "Microsoft Edge";v="136", "Not.A/Brand";v="99"',
|
||||
'content-type': 'application/x-www-form-urlencoded',
|
||||
'Accept': '*/*',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Connection': 'keep-alive',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Origin': 'https://www.dailymotion.com',
|
||||
'Pragma': 'no-cache',
|
||||
'Referer': 'https://www.dailymotion.com/',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Site': 'same-site',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
|
||||
'sec-ch-ua': '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'accept': '*/*',
|
||||
'origin': 'https://www.dailymotion.com',
|
||||
'sec-fetch-site': 'same-site',
|
||||
'sec-fetch-mode': 'cors',
|
||||
'sec-fetch-dest': 'empty',
|
||||
'referer': 'https://www.dailymotion.com/',
|
||||
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||
'priority': 'u=1, i',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
}
|
||||
u = uuid.uuid4()
|
||||
uuid_with_dash = str(u)
|
||||
|
@ -7,7 +7,6 @@ import argparse
|
||||
import redis
|
||||
import requests
|
||||
from requests import RequestException
|
||||
from urllib.parse import quote
|
||||
import DB
|
||||
|
||||
# —— 固定 Redis 连接配置 —— #
|
||||
@ -31,6 +30,21 @@ SIGN = "10099426b05c7119e9c4dbd6a7a0aa4e"
|
||||
|
||||
db = DB.DBVidcon()
|
||||
|
||||
def fetch_proxies3(region_code, n):
|
||||
url = "https://get-ip.thordata.net/api"
|
||||
params = {
|
||||
"td-customer": "Thor48890515",
|
||||
"sesstype": "2",
|
||||
"number": n,
|
||||
"country": region_code
|
||||
}
|
||||
try:
|
||||
resp = requests.get(url, params=params)
|
||||
except (RequestException, ValueError):
|
||||
time.sleep(1)
|
||||
return fetch_proxies3(region_code, n)
|
||||
result = resp.text.split("\r\n")
|
||||
return result
|
||||
|
||||
def fetch_proxies2(region_code, n):
|
||||
url = "http://" + region_code.lower() + "-pr.thordata.net:25000"
|
||||
@ -84,7 +98,7 @@ def refill_queue(r: redis.Redis, region_name: str, region_code: str,
|
||||
|
||||
to_fetch = batch - length
|
||||
print(f"[{time.strftime('%H:%M:%S')}] {key} 长度 {length} < {low},一次性拉取 {to_fetch} 条…")
|
||||
proxies = fetch_proxies(region_code, to_fetch)
|
||||
proxies = fetch_proxies3(region_code, to_fetch)
|
||||
if proxies:
|
||||
r.rpush(key, *proxies)
|
||||
print(f"[{time.strftime('%H:%M:%S')}] 已入队 {len(proxies)} 条 → 新长度 {r.llen(key)}")
|
||||
@ -117,4 +131,5 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
# main()
|
||||
fetch_proxies3('HK', 10)
|
Loading…
x
Reference in New Issue
Block a user