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

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,是否允许你通过代理

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记