检测ip的方法
(proxies_list)
| 23 | |
| 24 | |
| 25 | def check_us_ips(proxies_list): |
| 26 | """检测ip的方法""" |
| 27 | headers = { |
| 28 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36'} |
| 29 | |
| 30 | can_use = [] |
| 31 | for proxy in tqdm(proxies_list, desc="Checking ips"): |
| 32 | try: |
| 33 | response = requests.get('http://www.google.com', headers=headers, proxies=proxy, timeout=1) # 超时报错 |
| 34 | if response.status_code == 200: |
| 35 | can_use.append(proxy) |
| 36 | except Exception as error: |
| 37 | # print(error) |
| 38 | pass |
| 39 | return can_use |
| 40 | |
| 41 | |
| 42 | def get_china_free_proxy(pages=10): |