Преглед изворни кода

[update] 破解代理66 加速乐

jhao пре 7 година
родитељ
комит
f0c7a0f918
5 измењених фајлова са 46 додато и 29 уклоњено
  1. 2 2
      Config/setting.py
  2. 1 1
      ProxyGetter/CheckProxy.py
  3. 42 14
      ProxyGetter/getFreeProxy.py
  4. 0 12
      Util/utilFunction.py
  5. 1 0
      requirements.txt

+ 2 - 2
Config/setting.py

@@ -46,8 +46,8 @@ DATABASES = {
 # register the proxy getter function
 
 PROXY_GETTER = [
-    "freeProxyFirst",
-    "freeProxySecond",
+    "freeProxy01",
+    "freeProxy02",
     # "freeProxyThird",  # 网站已不能访问
     "freeProxyFourth",
     "freeProxyFifth",

+ 1 - 1
ProxyGetter/CheckProxy.py

@@ -67,4 +67,4 @@ class CheckProxy(object):
 
 if __name__ == '__main__':
     CheckProxy.checkAllGetProxyFunc()
-    CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxyFirst)
+    CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy01)

+ 42 - 14
ProxyGetter/getFreeProxy.py

@@ -49,24 +49,52 @@ class GetFreeProxy(object):
                     print(e)
 
     @staticmethod
-    def freeProxySecond(count=20):
+    def freeProxy02(count=20):
         """
         代理66 http://www.66ip.cn/
         :param count: 提取数量
         :return:
         """
         urls = [
-            "http://www.66ip.cn/mo.php?sxb=&tqsl={count}&port=&export=&ktip=&sxa=&submit=%CC%E1++%C8%A1&textarea=",
-            "http://www.66ip.cn/nmtq.php?getnum={count}"
-            "&isp=0&anonymoustype=0&start=&ports=&export=&ipaddress=&area=1&proxytype=2&api=66ip",
-            ]
-        request = WebRequest()
-        for _ in urls:
-            url = _.format(count=count)
-            html = request.get(url).content
-            ips = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}", html)
-            for ip in ips:
-                yield ip.strip()
+            "http://www.66ip.cn/mo.php?sxb=&tqsl={}&port=&export=&ktip=&sxa=&submit=%CC%E1++%C8%A1&textarea=",
+            "http://www.66ip.cn/nmtq.php?getnum={}&isp=0&anonymoustype=0&s"
+            "tart=&ports=&export=&ipaddress=&area=0&proxytype=2&api=66ip"
+        ]
+
+        try:
+            import execjs
+            import requests
+
+            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'}
+            session = requests.session()
+            src = session.get("http://www.66ip.cn/", headers=headers).text
+            src = src.split("</script>")[0] + '}'
+            src = src.replace("<script>", "function test() {")
+            src = src.replace("while(z++)try{eval(", ';var num=10;while(z++)try{var tmp=')
+            src = src.replace(");break}", ";num--;if(tmp.search('cookie') != -1 | num<0){return tmp}}")
+            ctx = execjs.compile(src)
+            src = ctx.call("test")
+            src = src[src.find("document.cookie="): src.find("};if((")]
+            src = src.replace("document.cookie=", "")
+            src = "function test() {var window={}; return %s }" % src
+            cookie = execjs.compile(src).call('test')
+            js_cookie = cookie.split(";")[0].split("=")[-1]
+        except Exception as e:
+            print(e)
+            return
+
+        for url in urls:
+            try:
+                html = session.get(url.format(count), cookies={"__jsl_clearance": js_cookie}, headers=headers).text
+                ips = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}", html)
+                for ip in ips:
+                    yield ip.strip()
+            except Exception as e:
+                print(e)
+                pass
 
     @staticmethod
     def freeProxyThird(days=1):
@@ -297,8 +325,8 @@ class GetFreeProxy(object):
 if __name__ == '__main__':
     from CheckProxy import CheckProxy
 
-    CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy01())
-    # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxySecond)
+    # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy01())
+    CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy02)
     # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxyThird)
     # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxyFourth)
     # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxyFifth)

+ 0 - 12
Util/utilFunction.py

@@ -12,16 +12,11 @@
 -------------------------------------------------
 """
 import requests
-import time
 from lxml import etree
 
-from Util.LogHandler import LogHandler
 from Util.WebRequest import WebRequest
 
-# logger = LogHandler(__name__, stream=False)
 
-
-# noinspection PyPep8Naming
 def robustCrawl(func):
     def decorate(*args, **kwargs):
         try:
@@ -34,7 +29,6 @@ def robustCrawl(func):
     return decorate
 
 
-# noinspection PyPep8Naming
 def verifyProxyFormat(proxy):
     """
     检查代理格式
@@ -47,7 +41,6 @@ def verifyProxyFormat(proxy):
     return True if len(_proxy) == 1 and _proxy[0] == proxy else False
 
 
-# noinspection PyPep8Naming
 def getHtmlTree(url, **kwargs):
     """
     获取html树
@@ -66,10 +59,6 @@ def getHtmlTree(url, **kwargs):
               }
     # TODO 取代理服务器用代理服务器访问
     wr = WebRequest()
-
-    # delay 2s for per request
-    time.sleep(2)
-
     html = wr.get(url=url, header=header).content
     return etree.HTML(html)
 
@@ -87,7 +76,6 @@ def tcpConnect(proxy):
     return True if result == 0 else False
 
 
-# noinspection PyPep8Naming
 def validUsefulProxy(proxy):
     """
     检验代理是否可用

+ 1 - 0
requirements.txt

@@ -3,5 +3,6 @@ werkzeug==0.11.15
 Flask==0.12
 requests==2.20.0
 lxml==3.7.2
+PyExecJS==1.5.1
 pymongo
 redis