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