代理檢驗是否可用

我爱你的發表於2024-06-30
def d_():
# python 3.6
ip_list = []
for i in get_proxies_list(500):

url = "http://www.baidu.com/"
# ip, port = "39.137.95.73", "8080"
# proxies = {"http": f"http://{ip}:{port}"}
proxies = i
# 空白位置為測試代理ip和代理ip使用埠

headers = {"User-Agent": "Mozilla/5.0"}
# 響應頭
try:
res = requests.get(url, proxies=proxies, headers=headers,timeout=3)
# 發起請求
print(res.status_code) # 返回響應碼
if res.status_code ==200:
ip_list.append(i)
except Exception as e:
print(e)
print(len(ip_list))
print(ip_list)
if __name__ == '__main__':
d_()

相關文章