diff --git a/oneforall/modules/search/gitee.py b/oneforall/modules/search/gitee.py new file mode 100644 index 0000000..0a840e0 --- /dev/null +++ b/oneforall/modules/search/gitee.py @@ -0,0 +1,72 @@ +import time +from bs4 import BeautifulSoup +from common.search import Search +from config import logger + + +class Gitee(Search): + def __init__(self, domain): + Search.__init__(self) + self.source = 'GiteeSearch' + self.module = 'Search' + self.addr = 'https://search.gitee.com/' + self.domain = self.register(domain) + self.header = self.get_header() + + def search(self, full_search=False): + """ + 向接口查询子域并做子域匹配 + """ + page_num = 1 + while True: + time.sleep(self.delay) + params = {'pageno': page_num, 'q': self.domain, 'type': 'code'} + try: + resp = self.get(self.addr, params=params) + except Exception as e: + logger.log('ERROR', e.args) + break + if resp.status_code != 200: + logger.log('ERROR', f'{self.source}模块搜索出错') + break + if 'class="empty-box"' in resp.text: + break + soup = BeautifulSoup(resp.text, 'lxml') + subdomains = self.match(self.domain, soup.text) + self.subdomains = self.subdomains.union(subdomains) + if not subdomains: + break + if not full_search: + # 搜索中发现搜索出的结果有完全重复的结果就停止搜索 + if subdomains.issubset(self.subdomains): + break + if '