|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 qwertyuiop1822 于 2018-10-10 18:39 编辑
在验证http://www.data5u.com/free/gwgn/index.shtml中的代理时
发现访问https的网站正常返回200,而且我写入html发现网页也正常,如百度、新浪,访问http的网站则连接超时。
为什么会出现这种情况呢?求各位大佬指教。
又遇到个不正常的事,不管代理怎么写,就算写成字母,比如"wwww",访问https://www.baidu.com返回码也是200
也就是说https并不能判断代理是否可用,他总是会返回正常内容。唯一合理的解释就是代理并没有生效,这是为什么?
我又试了http://www.89ip.cn/这个网站的代理
有的可以访问http://www.baidu.com,有的不能
代码如下:
- import requests
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.61 Safari/537.36',
- }
- proxies = {
- 'http':'http://46.45.19.138:8410'
- }
- #url = 'http://45.32.164.128/ip.php'
- url = 'https://www.baidu.com/'
- try:
- res = requests.get(url, headers=headers, proxies=proxies, timeout=10)
- print(res.status_code)
- except:
- pass
复制代码
来来我给你好好讲解下
proxies={'http':'http://46.45.19.138:8410'}#这里意思是访问http类型的网站,就用这个代理,你访问的https,其实就是没用代理,所以https就可以访问,那为什么http还是访问不了,那是这个代理有问题,为了http和https都用这个代理那就加上'https':'http://46.45.19.138:8410'
proxies={'http':'http://46.45.19.138:8410','https':'http://46.45.19.138:8410'
|
|