MCPcopy Create free account
hub / github.com/NanmiCoder/MediaCrawler / WanDouHttpProxy

Class WanDouHttpProxy

proxy/providers/wandou_http_proxy.py:36–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35
36class WanDouHttpProxy(ProxyProvider):
37
38 def __init__(self, app_key: str, num: int = 100):
39 """
40 WanDou HTTP proxy IP implementation
41 :param app_key: Open app_key, can be obtained through user center
42 :param num: Number of IPs extracted at once, maximum 100
43 """
44 self.proxy_brand_name = "WANDOUHTTP"
45 self.api_path = "https://api.wandouapp.com/"
46 self.params = {
47 "app_key": app_key,
48 "num": num,
49 }
50 self.ip_cache = IpCache()
51
52 async def get_proxy(self, num: int) -> List[IpInfoModel]:
53 """
54 :param num:
55 :return:
56 """
57
58 # Prioritize getting IP from cache
59 ip_cache_list = self.ip_cache.load_all_ip(
60 proxy_brand_name=self.proxy_brand_name
61 )
62 if len(ip_cache_list) >= num:
63 return ip_cache_list[:num]
64
65 # If the quantity in cache is insufficient, get from IP provider to supplement, then store in cache
66 need_get_count = num - len(ip_cache_list)
67 self.params.update({"num": min(need_get_count, 100)}) # Maximum 100
68 ip_infos = []
69 async with make_async_client() as client:
70 url = self.api_path + "?" + urlencode(self.params)
71 utils.logger.info(f"[WanDouHttpProxy.get_proxy] get ip proxy url:{url}")
72 response = await client.get(
73 url,
74 headers={
75 "User-Agent": "MediaCrawler https://github.com/NanmiCoder/MediaCrawler",
76 },
77 )
78 res_dict: Dict = response.json()
79 if res_dict.get("code") == 200:
80 data: List[Dict] = res_dict.get("data", [])
81 current_ts = utils.get_unix_timestamp()
82 for ip_item in data:
83 ip_info_model = IpInfoModel(
84 ip=ip_item.get("ip"),
85 port=ip_item.get("port"),
86 user="", # WanDou HTTP does not require username password authentication
87 password="",
88 expired_time_ts=utils.get_unix_time_from_time_str(
89 ip_item.get("expire_time")
90 ),
91 )
92 ip_key = f"WANDOUHTTP_{ip_info_model.ip}_{ip_info_model.port}"
93 ip_value = ip_info_model.model_dump_json()

Callers 1

new_wandou_http_proxyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected