From e66edb971728c8283ff7b66632d6c059cdf3dcbb Mon Sep 17 00:00:00 2001 From: Jing Ling Date: Sun, 2 Feb 2020 18:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Gitee=E7=A0=81=E4=BA=91?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oneforall/modules/search/gitee.py | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 oneforall/modules/search/gitee.py 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 '
  • ' in resp.text: + break + if page_num > 100: + break + page_num += 1 + + def run(self): + """ + 类执行入口 + """ + self.begin() + self.search() + self.finish() + self.save_json() + self.gen_result() + self.save_db() + + +def do(domain): # 统一入口名字 方便多线程调用 + """ + 类统一调用入口 + + :param str domain: 域名 + """ + query = Gitee(domain) + query.run() + + +if __name__ == '__main__': + do('example.com')