feat: implement fetch_proxies2 method to retrieve proxy IPs from external API
This commit is contained in:
parent
203eb54d6c
commit
512cad19c9
@ -44,9 +44,26 @@ def fetch_proxies3(region_code, n):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# def fetch_proxies2(region_code, n):
|
def fetch_proxies2(region_code, n):
|
||||||
# url = "http://" + region_code.lower() + "-pr.thordata.net:25000"
|
url = f"http://api.ipipgo.com/ip?cty={region_code}&c={n}&pt=1&ft=json&pat=\n&rep=1&key=625ce417"
|
||||||
# return [url for _ in range(n)
|
try:
|
||||||
|
res = requests.get(url)
|
||||||
|
data_json = res.json()
|
||||||
|
print(data_json)
|
||||||
|
except (RequestException, ValueError):
|
||||||
|
time.sleep(1)
|
||||||
|
return fetch_proxies1(region_code, n)
|
||||||
|
arr = data_json["data"] or []
|
||||||
|
if not arr:
|
||||||
|
time.sleep(1)
|
||||||
|
return fetch_proxies1(region_code, n)
|
||||||
|
result = []
|
||||||
|
for item in arr:
|
||||||
|
ip = item["ip"]
|
||||||
|
port = item["port"]
|
||||||
|
result.append(f"http://{ip}:{port}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
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=socks5"
|
url = f"http://api.proxy.roxlabs.io/getProxyIp?num={n}&return_type=json&lb=1&sb=&flow=1®ions={region_code}&protocol=socks5"
|
||||||
@ -186,4 +203,5 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
# main()
|
||||||
|
fetch_proxies2('TW',2)
|
Loading…
x
Reference in New Issue
Block a user