Przeglądaj źródła

add xiladaili proxy source and add lxml in requirements.txt

linupy 6 lat temu
rodzic
commit
a9ef0f407e
2 zmienionych plików z 34 dodań i 1 usunięć
  1. 32 0
      proxypool/crawlers/public/xiladaili.py
  2. 2 1
      requirements.txt

+ 32 - 0
proxypool/crawlers/public/xiladaili.py

@@ -0,0 +1,32 @@
+from proxypool.schemas.proxy import Proxy
+from proxypool.crawlers.base import BaseCrawler
+from lxml import etree
+
+BASE_URL = "http://www.xiladaili.com/"
+MAX_PAGE = 5
+
+
+class XiladailiCrawler(BaseCrawler):
+    """
+    xiladaili crawler, http://www.xiladaili.com/
+    """
+    urls = ["http://www.xiladaili.com/"]
+
+    def parse(self, html):
+        """
+        parse html file to get proxies
+        :return:
+        """
+        etree_html = etree.HTML(html)
+        ip_ports = etree_html.xpath("//tbody/tr/td[1]/text()")
+
+        for ip_port in ip_ports:
+            host = ip_port.partition(":")[0]
+            port = ip_port.partition(":")[2]
+            yield Proxy(host=host, port=port)
+
+
+if __name__ == '__main__':
+    crawler = XiladailiCrawler()
+    for proxy in crawler.crawl():
+        print(proxy)

+ 2 - 1
requirements.txt

@@ -7,4 +7,5 @@ requests==2.22.0
 loguru==0.3.2
 pyquery==1.4.0
 supervisor==4.1.0
-redis==2.10.6
+redis==2.10.6
+lxml==4.3.3