Skip to content

Commit

Permalink
Fixed GoogleCSE
Browse files Browse the repository at this point in the history
Fixed API calls
  • Loading branch information
laramies committed Dec 19, 2018
1 parent 1006e05 commit b7e7e28
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions discovery/googleCSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import time
import requests
from discovery.constants import *

class search_googleCSE:

Expand All @@ -14,6 +13,7 @@ def __init__(self, word, limit, start):
self.totalresults = ""
self.server = "www.googleapis.com"
self.hostname = "www.googleapis.com"
self.userAgent = "(Mozilla/5.0 (Windows; U; Windows NT 6.0;en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"
self.quantity = "10"
self.limit = limit
self.counter = 1
Expand All @@ -22,17 +22,19 @@ def __init__(self, word, limit, start):
print("You need an API key in order to use the Hunter search engine. You can get one here: https://cse.google.com")
sys.exit()
self.cse_id = ""

self.lowRange = start
self.highRange = start+100

def do_search(self):
url = 'https://' + self.server + "/customsearch/v1?key=" + self.api_key + "&highRange=" + str(self.highRange) \
+ '&lowRange=' + str(self.lowRange) + '&cx=' + self.cse_id + "&start=" + str(self.counter) + \
"&q=%40\"" + self.word + "\""
url = 'https://' + self.server + "/customsearch/v1?key=" + self.api_key + "&highrange=" + str(self.highRange) \
+ '&lowrange=' + str(self.lowRange) + '&cx=' + self.cse_id + "&start=" + str(self.counter) + \
"&q="+ self.word
headers = {
'Host': self.server,
'User-agent': getUserAgent()
'User-agent': self.userAgent
}

h = requests.get(url=url, headers=headers)
self.results = h.text
self.totalresults += self.results
Expand All @@ -43,7 +45,7 @@ def do_search_files(self,files):
"&q=filetype:" + files + "%20site:" + self.word
headers = {
'Host': self.server,
'User-agent': getUserAgent()
'User-agent': self.userAgent
}
h = requests.get(url=url, headers=headers)
self.results = h.text
Expand Down Expand Up @@ -99,6 +101,6 @@ def store_results(self):
def process_files(self, files):
while self.counter <= self.limit:
self.do_search_files(files)
time.sleep(getDelay())
time.sleep(1)
self.counter += 100
print("\tSearching " + str(self.counter) + " results...")

0 comments on commit b7e7e28

Please sign in to comment.