From 403a3fefcbc7d1cdd50efab1748c4730467e41d8 Mon Sep 17 00:00:00 2001 From: shmilylty Date: Thu, 22 Aug 2019 19:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Github=E5=AD=90=E5=9F=9F?= =?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/github.py | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 oneforall/modules/search/github.py diff --git a/oneforall/modules/search/github.py b/oneforall/modules/search/github.py new file mode 100644 index 0000000..37ee1f4 --- /dev/null +++ b/oneforall/modules/search/github.py @@ -0,0 +1,57 @@ +import time + +from common.query import Query + + +class Github(Query): + def __init__(self, domain): + Query.__init__(self) + self.source = 'GithubSearch' + self.module = 'Search' + self.addr = 'https://github.com/search' + self.domain = self.register(domain) + + def query(self): + """ + 向接口查询子域并做子域匹配 + """ + page_num = 1 + while True: + time.sleep(self.delay) + self.header = self.get_header() + self.proxy = self.get_proxy(self.source) + params = {'p': page_num, 'q': f'"{self.domain}"', 'type': 'Code'} + resp = self.get(url=self.addr, params=params) + print(resp.url) + if not resp: + return + subdomains = self.match(self.domain, resp.text) + self.subdomains = self.subdomains.union(subdomains) + if 'class="next_page disabled"' in resp.text: + break + page_num += 1 + + def run(self): + """ + 类执行入口 + """ + self.begin() + self.query() + self.finish() + self.save_json() + self.gen_result() + self.save_db() + + +def do(domain): # 统一入口名字 方便多线程调用 + """ + 类统一调用入口 + + :param str domain: 域名 + """ + query = Github(domain) + query.run() + + +if __name__ == '__main__': + do('example.com')