|
@@ -2,6 +2,7 @@ from pyquery import PyQuery as pq
|
|
|
from proxypool.schemas.proxy import Proxy
|
|
from proxypool.schemas.proxy import Proxy
|
|
|
from proxypool.crawlers.base import BaseCrawler
|
|
from proxypool.crawlers.base import BaseCrawler
|
|
|
from loguru import logger
|
|
from loguru import logger
|
|
|
|
|
+import re
|
|
|
|
|
|
|
|
|
|
|
|
|
BASE_URL = 'https://www.zdaye.com/dayProxy/{page}.html'
|
|
BASE_URL = 'https://www.zdaye.com/dayProxy/{page}.html'
|
|
@@ -11,50 +12,47 @@ class ZhandayeCrawler(BaseCrawler):
|
|
|
"""
|
|
"""
|
|
|
zhandaye crawler, https://www.zdaye.com/dayProxy/
|
|
zhandaye crawler, https://www.zdaye.com/dayProxy/
|
|
|
"""
|
|
"""
|
|
|
- urls = [BASE_URL.format(page=page) for page in range(1, MAX_PAGE)]
|
|
|
|
|
-
|
|
|
|
|
|
|
+ urls_catalog = [BASE_URL.format(page=page) for page in range(1, MAX_PAGE)]
|
|
|
headers = {
|
|
headers = {
|
|
|
'User-Agent': 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'
|
|
'User-Agent': 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'
|
|
|
}
|
|
}
|
|
|
|
|
+ urls = []
|
|
|
|
|
|
|
|
def crawl(self):
|
|
def crawl(self):
|
|
|
- for url in self.urls:
|
|
|
|
|
|
|
+ self.crawl_catalog()
|
|
|
|
|
+ yield from super().crawl()
|
|
|
|
|
+
|
|
|
|
|
+ def crawl_catalog(self):
|
|
|
|
|
+ for url in self.urls_catalog:
|
|
|
logger.info(f'fetching {url}')
|
|
logger.info(f'fetching {url}')
|
|
|
html = self.fetch(url, headers=self.headers)
|
|
html = self.fetch(url, headers=self.headers)
|
|
|
- self.parse(html)
|
|
|
|
|
|
|
+ self.parse_catalog(html)
|
|
|
|
|
|
|
|
- def parse(self, html):
|
|
|
|
|
|
|
+ def parse_catalog(self, html):
|
|
|
"""
|
|
"""
|
|
|
parse html file to get proxies
|
|
parse html file to get proxies
|
|
|
:return:
|
|
:return:
|
|
|
"""
|
|
"""
|
|
|
doc = pq(html)
|
|
doc = pq(html)
|
|
|
for item in doc('#J_posts_list .thread_item div div p a').items():
|
|
for item in doc('#J_posts_list .thread_item div div p a').items():
|
|
|
- post = 'https://www.zdaye.com' + item.attr('href')
|
|
|
|
|
- logger.info(f'get detail url: {post}')
|
|
|
|
|
- ZhandayeDetailCrawler(post).crawl()
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-class ZhandayeDetailCrawler(BaseCrawler):
|
|
|
|
|
- urls = []
|
|
|
|
|
- ignore = True
|
|
|
|
|
-
|
|
|
|
|
- def __init__(self, url):
|
|
|
|
|
- self.urls.append(url)
|
|
|
|
|
- super().__init__()
|
|
|
|
|
|
|
+ url = 'https://www.zdaye.com' + item.attr('href')
|
|
|
|
|
+ logger.info(f'get detail url: {url}')
|
|
|
|
|
+ self.urls.append(url)
|
|
|
|
|
|
|
|
def parse(self, html):
|
|
def parse(self, html):
|
|
|
doc = pq(html)
|
|
doc = pq(html)
|
|
|
trs = doc('.cont br').items()
|
|
trs = doc('.cont br').items()
|
|
|
for tr in trs:
|
|
for tr in trs:
|
|
|
line = tr[0].tail
|
|
line = tr[0].tail
|
|
|
- host = line.split(':')[0]
|
|
|
|
|
- port = line.split(':')[1][:4]
|
|
|
|
|
- yield Proxy(host=host, port=port)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ match = re.search(r'(\d+\.\d+\.\d+\.\d+):(\d+)', line)
|
|
|
|
|
+ if match:
|
|
|
|
|
+ host = match.group(1)
|
|
|
|
|
+ port = match.group(2)
|
|
|
|
|
+ yield Proxy(host=host, port=port)
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
crawler = ZhandayeCrawler()
|
|
crawler = ZhandayeCrawler()
|
|
|
for proxy in crawler.crawl():
|
|
for proxy in crawler.crawl():
|
|
|
print(proxy)
|
|
print(proxy)
|
|
|
|
|
+
|