当自已使用代理抓取网站时,怎么才能知道自己的代理,设置成功了
1、代理测试目标网站:
http://www.httpbin.org/ip
https://ip.sb
2、代码测试
import requests
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
}
test_url = "http://www.httpbin.org/ip"
test_url2 = "http://icanhazip.com/"
# test_url2 = "https://ip.sb/" #未测试
proxies = {
"https": "10.126.43.9:3134",
"http": "10.126.43.9:3134"
}
res = requests.get(test_url2, headers=headers, proxies=proxies)
print(res.text)
# 返回结果是代理IP,证明设置成功