鱼C论坛

 找回密码
 立即注册
查看: 599|回复: 1

requests.get返回错误捕获?

[复制链接]
发表于 2018-7-22 16:57:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. def ip_testing(ip_list, header):
  2.     result_last = []
  3.     i = 0
  4.     my_ip = myself_ip(header)
  5.     for i in ip_list:
  6.         result ={}
  7.         ip_http = sorted(i.keys())[0]
  8.         ip_num = sorted(i.values())[0]
  9.         proxy_support = {ip_http: ip_num}
  10.         url = 'http://ip.chinaz.com/getip.aspx'
  11.         try:
  12.             r = requests.get(url, headers=header, proxies=proxy_support,timeout=10)

  13.         except requests.exceptions.ConnectTimeout:
  14.             NETWORK_STATUS = False
  15.         except requests.exceptions.Timeout:
  16.             REQUEST_TIMEOUT = True

  17.             r.status_code
  18.             print('r.status_code=%s' % r.status_code)
  19.             i =i + 1

  20.             if r.text == my_ip or REQUEST_TIMEOUT or not NETWORK_STATUS:
  21.                 continue
  22.             else:
  23.                 result[ip_http] = ip_num
  24.                 result_last.append(result)        
  25.     return result_last
复制代码


    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='123.180.68.72', port=8010): Max retries exceeded with url: http://ip.chinaz.com/getip.aspx (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003D24748>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

用坛友的代码爬取代理IP, requests.get返回错误,怎么捕获,让程序继续跑?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-7-22 19:37:34 | 显示全部楼层
代理不行换代理啊。

现在这代理不好找。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 17:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表