验证代理是否可用
从代理网上获取代理IP之后,还得查看代理是否可用.有两种方法进行测试
- 利用requests库挂上代理访问网站,监测是否访问成功
1
2
3
4
5
6
7
8
9
10
11
12
13import requests
proxies={
"http":"http://185.44.15.228:3130",
"https":"http://185.44.15.228:3130",
}
try:
requests.get('http://www.baidu.com', proxies=proxies)
except:
print('failed')
else:
print('success') - 利用telnetlib库对代理ip进行测试,监测是否成功
1
2
3
4
5
6
7import telnetlib
try:
tel=telnetlib.Telnet('121.199.25.64',port='80',timeout=10)
except:
print('failed')
else:
print('success')
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 SHIELD!
评论