소스 검색

添加更加严谨的代理校验规则(一些非法代理也会返回200状态码)

incoding 7 년 전
부모
커밋
3c3ddaff09
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      Util/utilFunction.py

+ 1 - 1
Util/utilFunction.py

@@ -100,7 +100,7 @@ def validUsefulProxy(proxy):
     try:
     try:
         # 超过20秒的代理就不要了
         # 超过20秒的代理就不要了
         r = requests.get('http://httpbin.org/ip', proxies=proxies, timeout=10, verify=False)
         r = requests.get('http://httpbin.org/ip', proxies=proxies, timeout=10, verify=False)
-        if r.status_code == 200:
+        if r.status_code == 200 and r.headers['content-type'].lower().find('application/json') != -1 and r.json()['origin']:
             # logger.info('%s is ok' % proxy)
             # logger.info('%s is ok' % proxy)
             return True
             return True
     except Exception as e:
     except Exception as e: