the_koala_uncle 2017-08-01 07:19 采纳率: 50%
浏览 2775

python 代理问题 代理验证那里一直通过不了

HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: http://ip.chinaz.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 11004] getaddrinfo failed',)))

代理一直不成功,不知道代码哪里错了、
#!python3
#get Proxy

import requests
from bs4 import BeautifulSoup
from collections import deque

#获取ip
def getProxy(number):
url='http://www.xicidaili.com/nn/'

headers={    
    'Host':'www.xicidaili.com',
    'Referer':'http://www.so.com/link?m=aPh8cfhKQ2NFc1RnOMWh5a7QC3YM7q5XuBGmyxUXTySoLTq0kmNWg8UN8kM5wC0%2Bu695HB4%2FdearMLWKRvF7xUQKAWXc5tZBALokisY82c%2FhO%2BvCXgOHaTetN06GBGCHnwXJcgQUJQk0%3D',
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
    }
Deque=deque()
res=requests.get(url,headers=headers)
soup=BeautifulSoup(res.text,'lxml')
content1=soup.find_all('td',limit=number*10)[1::10]
content2=soup.find_all('td',limit=number*10)[2::10]
content3=soup.find_all('td',limit=number*10)[8::10]
content4=soup.find_all('div',class_='bar',limit=number*10)[0::2]


for i in range(number):
    if judge(content4[i].get('title'),content3[i].string):
        one=[content1[i].string,content2[i].string,content4[i].get('title'),content3[i].string]
        Deque.append(one)
        print('Get one.........')
    else:
        print('Delete one......')
return(Deque)

#判断是否满足使用要求
def judge(speed,tim):
if float(speed[0:-1])>1.3: # 调时间,单位是秒
return(False)
else:
pass

if tim[-1]=='天':
    t=int(tim[0:-1])*24*60
elif tim[-1]=='时':
    t=int(tim[0:-2])*60
elif tim[-1]=='钟':
    t=int(tim[0:-2])
else:
    t=0
if t<10:                 #调iP可以使用时限,单位是分钟
    return(False)
else:
    pass
return(True)

#连接网络检验
def test(ip,port):
url='http://ip.chinaz.com/'

headers={
    'Host':'ip.chinaz.com',
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
    }

proxies={'http':'http//'+ip+':'+port,'https':'https//'+ip+':'+port}


try:
    res=requests.get(url,headers=headers,proxies=proxies)
    ree=re.compile(r'</span>(.*?)<span class')
    ipp=ree.findall(res.text)
    ipre=ipp[0].strip()
    if ipre=='':#个人ip地址
        print('本机ip')
    else:
        print(ipre)
except Exception as e: 
    print('Not working......')
    print(e)

def start(numm):

got=getProxy(numm)
print('-----------------------')
print('Testing ip now...')
for e in got:
test(e[0],e[1])
#d.popleft()
start(5)

  • 写回答

1条回答 默认 最新

  • oyljerry 2017-08-01 08:44
    关注

    错误是你无法连接你的proxy,先看你的网络能否访问proxy,是否允许你通过代理

    评论

报告相同问题?

悬赏问题

  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问