fix: 更新 fetch_proxies4 方法以使用 socks5 协议并修正代理 IP 格式
This commit is contained in:
parent
bcab7d1ac1
commit
203eb54d6c
@ -49,7 +49,7 @@ def fetch_proxies3(region_code, n):
|
|||||||
# return [url for _ in range(n)
|
# return [url for _ in range(n)
|
||||||
|
|
||||||
def fetch_proxies4(region_code, n):
|
def fetch_proxies4(region_code, n):
|
||||||
url = f"http://api.proxy.roxlabs.io/getProxyIp?num={n}&return_type=json&lb=1&sb=&flow=1®ions={region_code}&protocol=http"
|
url = f"http://api.proxy.roxlabs.io/getProxyIp?num={n}&return_type=json&lb=1&sb=&flow=1®ions={region_code}&protocol=socks5"
|
||||||
try:
|
try:
|
||||||
res = requests.get(url)
|
res = requests.get(url)
|
||||||
data_json = res.json()
|
data_json = res.json()
|
||||||
@ -64,7 +64,7 @@ def fetch_proxies4(region_code, n):
|
|||||||
for item in arr:
|
for item in arr:
|
||||||
ip = item["ip"]
|
ip = item["ip"]
|
||||||
port = item["port"]
|
port = item["port"]
|
||||||
result.append(f"http://{ip}:{port}")
|
result.append(f"socks5h://{ip}:{port}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def fetch_proxies1(region_code, n):
|
def fetch_proxies1(region_code, n):
|
||||||
@ -153,7 +153,7 @@ def refill_queue(r: redis.Redis, region_name: str, region_code: str,
|
|||||||
|
|
||||||
to_fetch = batch - length
|
to_fetch = batch - length
|
||||||
print(f"[{time.strftime('%H:%M:%S')}] {key} 长度 {length} < {low},一次性拉取 {to_fetch} 条…")
|
print(f"[{time.strftime('%H:%M:%S')}] {key} 长度 {length} < {low},一次性拉取 {to_fetch} 条…")
|
||||||
proxies = fetch_proxies(region_code, to_fetch)
|
proxies = fetch_proxies4(region_code, to_fetch)
|
||||||
if proxies:
|
if proxies:
|
||||||
r.rpush(key, *proxies)
|
r.rpush(key, *proxies)
|
||||||
print(f"[{time.strftime('%H:%M:%S')}] 已入队 {len(proxies)} 条 → 新长度 {r.llen(key)}")
|
print(f"[{time.strftime('%H:%M:%S')}] 已入队 {len(proxies)} 条 → 新长度 {r.llen(key)}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user