import time from client.subdomain.oneforall.common.search import Search class Bing(Search): def __init__(self, domain): Search.__init__(self) self.domain = domain self.module = 'Search' self.source = 'BingSearch' self.init = 'https://www.bing.com/' self.addr = 'https://www.bing.com/search' self.limit_num = 1000 # 限制搜索条数 def search(self, domain, filtered_subdomain='', full_search=False): """ 发送搜索请求并做子域匹配 :param str domain: 域名 :param str filtered_subdomain: 过滤的子域 :param bool full_search: 全量搜索 """ self.page_num = 0 # 二次搜索重新置0 self.header = self.get_header() self.proxy = self.get_proxy(self.source) resp = self.get(self.init) if not resp: return self.cookie = resp.cookies # 获取cookie bing在搜索时需要带上cookie while True: time.sleep(self.delay) self.proxy = self.get_proxy(self.source) query = 'site:' + domain + filtered_subdomain params = {'q': query, 'first': self.page_num, 'count': self.per_page_num} resp = self.get(self.addr, params) if not resp: return subdomains = self.match(domain, resp.text) if not subdomains: # 搜索没有发现子域名则停止搜索 break if not full_search: # 搜索中发现搜索出的结果有完全重复的结果就停止搜索 if subdomains.issubset(self.subdomains): break # 合并搜索子域名搜索结果 self.subdomains = self.subdomains.union(subdomains) # 搜索页面没有出现下一页时停止搜索 if '