parse html file to get proxies :return:
(self, html)
| 14 | urls = [BASE_URL.format(stype=stype,page=i) for stype in range(1,3) for i in range(1, 8)] |
| 15 | |
| 16 | def parse(self, html): |
| 17 | """ |
| 18 | parse html file to get proxies |
| 19 | :return: |
| 20 | """ |
| 21 | ip_address = re.compile('<tr>\s*<td>(.*?)</td>\s*<td>(.*?)</td>') |
| 22 | # \s * 匹配空格,起到换行作用 |
| 23 | re_ip_address = ip_address.findall(html) |
| 24 | for address, port in re_ip_address: |
| 25 | proxy = Proxy(host=address.strip(), port=int(port.strip())) |
| 26 | yield proxy |
| 27 | |
| 28 | |
| 29 | if __name__ == '__main__': |