iphai.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from proxypool.crawlers.base import BaseCrawler
  2. from proxypool.schemas.proxy import Proxy
  3. import re
  4. BASE_URL = 'http://www.iphai.com/'
  5. class IPHaiCrawler(BaseCrawler):
  6. """
  7. iphai crawler, http://www.iphai.com/
  8. """
  9. urls = [BASE_URL]
  10. ignore = True
  11. def parse(self, html):
  12. """
  13. parse html file to get proxies
  14. :return:
  15. """
  16. find_tr = re.compile('<tr>(.*?)</tr>', re.S)
  17. trs = find_tr.findall(html)
  18. for s in range(1, len(trs)):
  19. find_ip = re.compile('<td>\s+(\d+\.\d+\.\d+\.\d+)\s+</td>', re.S)
  20. re_ip_address = find_ip.findall(trs[s])
  21. find_port = re.compile('<td>\s+(\d+)\s+</td>', re.S)
  22. re_port = find_port.findall(trs[s])
  23. for address, port in zip(re_ip_address, re_port):
  24. proxy = Proxy(host=address.strip(), port=int(port.strip()))
  25. yield proxy
  26. if __name__ == '__main__':
  27. crawler = IPHaiCrawler()
  28. for proxy in crawler.crawl():
  29. print(proxy)