xiladaili.py 807 B

1234567891011121314151617181920212223242526272829303132
  1. from proxypool.schemas.proxy import Proxy
  2. from proxypool.crawlers.base import BaseCrawler
  3. from lxml import etree
  4. BASE_URL = "http://www.xiladaili.com/"
  5. MAX_PAGE = 5
  6. class XiladailiCrawler(BaseCrawler):
  7. """
  8. xiladaili crawler, http://www.xiladaili.com/
  9. """
  10. urls = ["http://www.xiladaili.com/"]
  11. def parse(self, html):
  12. """
  13. parse html file to get proxies
  14. :return:
  15. """
  16. etree_html = etree.HTML(html)
  17. ip_ports = etree_html.xpath("//tbody/tr/td[1]/text()")
  18. for ip_port in ip_ports:
  19. host = ip_port.partition(":")[0]
  20. port = ip_port.partition(":")[2]
  21. yield Proxy(host=host, port=port)
  22. if __name__ == '__main__':
  23. crawler = XiladailiCrawler()
  24. for proxy in crawler.crawl():
  25. print(proxy)