Selaa lähdekoodia

Merge branch 'master' of https://github.com/feng409/proxy_pool into feng409-master

 Conflicts:
	doc/release_notes.md
jhao 6 vuotta sitten
vanhempi
sitoutus
4bde3bb04d
3 muutettua tiedostoa jossa 12 lisäystä ja 2 poistoa
  1. 4 0
      Config/ConfigGetter.py
  2. 2 1
      Config/setting.py
  3. 6 1
      Util/utilFunction.py

+ 4 - 0
Config/ConfigGetter.py

@@ -57,6 +57,10 @@ class ConfigGetter(object):
     def host_port(self):
         return SERVER_API.get("PORT", 5010)
 
+    @LazyProperty
+    def verify_host(self):
+        return VERIFY_HOST
+
 
 config = ConfigGetter()
 

+ 2 - 1
Config/setting.py

@@ -10,7 +10,6 @@
                    2019/2/15:
 -------------------------------------------------
 """
-
 import sys
 from os import getenv
 from logging import getLogger
@@ -73,6 +72,8 @@ SERVER_API = {
     "PORT": 5010  # port number to which the server listens to
 }
 
+VERIFY_HOST = getenv('proxy_verify_host', 'http://www.baidu.com')
+
 
 class ConfigError(BaseException):
     pass

+ 6 - 1
Util/utilFunction.py

@@ -15,6 +15,7 @@ import requests
 from lxml import etree
 
 from Util.WebRequest import WebRequest
+from Config.ConfigGetter import config
 
 
 def robustCrawl(func):
@@ -85,8 +86,12 @@ def validUsefulProxy(proxy):
     if isinstance(proxy, bytes):
         proxy = proxy.decode("utf8")
     proxies = {"http": "http://{proxy}".format(proxy=proxy)}
+    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
+               'Accept': '*/*',
+               'Connection': 'keep-alive',
+               'Accept-Language': 'zh-CN,zh;q=0.8'}
     try:
-        r = requests.get('http://www.baidu.com', proxies=proxies, timeout=10, verify=False)
+        r = requests.head(config.verify_host, headers=headers, proxies=proxies, timeout=10, verify=False)
         if r.status_code == 200:
             return True
     except Exception as e: