2018-12-28 08:49:56 +08:00
|
|
|
from discovery.constants import *
|
2019-01-06 17:50:07 +08:00
|
|
|
from lib.core import *
|
2019-01-11 10:09:47 +08:00
|
|
|
from parsers import myparser
|
|
|
|
import requests
|
|
|
|
import time
|
2018-12-28 08:49:56 +08:00
|
|
|
|
|
|
|
|
2019-01-06 17:50:07 +08:00
|
|
|
class SearchBaidu:
|
2018-12-28 08:49:56 +08:00
|
|
|
|
|
|
|
def __init__(self, word, limit):
|
|
|
|
self.word = word
|
|
|
|
self.total_results = ""
|
2019-01-13 14:17:06 +08:00
|
|
|
self.server = 'www.baidu.com'
|
|
|
|
self.hostname = 'www.baidu.com'
|
2018-12-28 08:49:56 +08:00
|
|
|
self.limit = limit
|
|
|
|
self.counter = 0
|
|
|
|
|
|
|
|
def do_search(self):
|
2019-01-13 14:17:06 +08:00
|
|
|
url = 'http://' + self.server + '/s?wd=%40' + self.word + '&pn=' + str(self.counter) + '&oq=' + self.word
|
2018-12-28 08:49:56 +08:00
|
|
|
headers = {
|
|
|
|
'Host': self.hostname,
|
2019-01-06 17:50:07 +08:00
|
|
|
'User-agent': Core.get_user_agent()
|
2018-12-28 08:49:56 +08:00
|
|
|
}
|
|
|
|
h = requests.get(url=url, headers=headers)
|
|
|
|
time.sleep(getDelay())
|
|
|
|
self.total_results += h.text
|
|
|
|
|
|
|
|
def process(self):
|
|
|
|
while self.counter <= self.limit and self.counter <= 1000:
|
|
|
|
self.do_search()
|
2019-01-11 10:09:47 +08:00
|
|
|
print(f'\tSearching {self.counter} results.')
|
2018-12-28 08:49:56 +08:00
|
|
|
self.counter += 10
|
|
|
|
|
|
|
|
def get_emails(self):
|
2019-01-06 17:50:07 +08:00
|
|
|
rawres = myparser.Parser(self.total_results, self.word)
|
2018-12-28 08:49:56 +08:00
|
|
|
return rawres.emails()
|
|
|
|
|
|
|
|
def get_hostnames(self):
|
2019-01-06 17:50:07 +08:00
|
|
|
rawres = myparser.Parser(self.total_results, self.word)
|
2018-12-28 08:49:56 +08:00
|
|
|
return rawres.hostnames()
|