def doGoogleSearch(self, query, start = 0, maxResults = 10, filter = 1, restrict = '', safeSearch = 0, language = '', inputencoding = 'UTF-8', outputencoding = 'UTF-8', http_proxy=None): #doGoogleSearch google.setLicense(self.license_key) l_data = google.doGoogleSearch( query, start, maxResults, filter, restrict, safeSearch, language, inputencoding, outputencoding, self.license_key, http_proxy) l_meta = { 'documentFiltering' : l_data.meta.documentFiltering, 'searchComments' : l_data.meta.searchComments, 'estimatedTotalResultsCount' : l_data.meta.estimatedTotalResultsCount, 'estimateIsExact' : l_data.meta.estimateIsExact, 'searchQuery' : l_data.meta.searchQuery, 'startIndex' : l_data.meta.startIndex, 'endIndex' : l_data.meta.endIndex, 'searchTips' : l_data.meta.searchTips, 'directoryCategories' : l_data.meta.directoryCategories, 'searchTime' : l_data.meta.searchTime, } l_result = [] for r in l_data.results: l_result.append( { 'URL' : r.URL, 'title' : r.title, 'snippet' : r.snippet, 'cachedSize' : r.cachedSize, 'relatedInformationPresent' : r.relatedInformationPresent, 'hostName' : r.hostName, 'directoryCategory' : r.directoryCategory, 'directoryTitle' : r.directoryTitle, 'summary' : r.summary, } ) return (l_meta, l_result)
def doGoogleSearch(self, query, start, maxResults, filter, restrict, safeSearch, language, inputencoding, outputencoding, http_proxy): #doGoogleSearch try: l_license_key = self.license google.setLicense(l_license_key) return self._doGoogleSearch(query, start, maxResults, filter, restrict, safeSearch, language, inputencoding, outputencoding, http_proxy, l_license_key) except faultType, error: # if (utils.utStringInString('Exception from service', error.faultstring)) or (utils.utStringInString('Invalid authorization key', error.faultstring)) or (self.utStringInString('Daily limit of 1000 queries exceeded', error.faultstring)): # return self.doGoogleSearch(query, # start, # maxResults, # filter, # restrict, # safeSearch, # language, # inputencoding, # outputencoding, # http_proxy) # else: # return ({}, [], 'err') self.error_log.raising(sys.exc_info()) return ({}, [], 'err')
def testSetInvalidKey(self): """setting invalid module-level license key should fail with faultType""" google.setLicense(self.badkey) self.assertRaises(GoogleSOAPFacade.faultType, google.doGoogleSearch, q=self.q)
def __init__(self): global the_bot the_bot = self google.setLicense('eDOOWdhQFHJhZ+4WTjIzq19UDl9vSNa+') self.logfile = open('dudebot.log', 'a') self.plugin_list = {} self.plugins_that_hook_privmsg = [] self.has_joined = False self.user_list = Users() tmp = '^' + self.nickname + '[,|:|;]?\s+(\S+)(?:\s+(.*))?' self.command_regex = re.compile(tmp) self.query_command_regex = re.compile('^\s*(\S+)(?:\s+(.*))?') self.loadPlugins()
def getGoogleTotalResultsCount(s): google.setLicense('...') # must get your own key! ustr = unicode(s,'shiftjis') flg = True while flg: try: data = google.doGoogleSearch(ustr) except: print sys.exc_info() time.sleep(5) else: flg = False return data.meta.estimatedTotalResultsCount
def getGoogleTotalResultsCount(s): keys = open("./googlelicense.txt","r").read().rstrip("\n").split("\n") google.setLicense(random.choice(keys)) # must get your own key! ustr = unicode(s,'shiftjis') fsuccess = False while fsuccess == False: try: data = google.doGoogleSearch(ustr) except: print sys.exc_info() time.sleep(5) else: fsuccess = True return data.meta.estimatedTotalResultsCount
def doGoogleSearch(self, query, start=0, maxResults=10, filter=1, restrict='', safeSearch=0, language='', inputencoding='UTF-8', outputencoding='UTF-8', http_proxy=None): #doGoogleSearch google.setLicense(self.license_key) l_data = google.doGoogleSearch(query, start, maxResults, filter, restrict, safeSearch, language, inputencoding, outputencoding, self.license_key, http_proxy) l_meta = { 'documentFiltering': l_data.meta.documentFiltering, 'searchComments': l_data.meta.searchComments, 'estimatedTotalResultsCount': l_data.meta.estimatedTotalResultsCount, 'estimateIsExact': l_data.meta.estimateIsExact, 'searchQuery': l_data.meta.searchQuery, 'startIndex': l_data.meta.startIndex, 'endIndex': l_data.meta.endIndex, 'searchTips': l_data.meta.searchTips, 'directoryCategories': l_data.meta.directoryCategories, 'searchTime': l_data.meta.searchTime, } l_result = [] for r in l_data.results: l_result.append({ 'URL': r.URL, 'title': r.title, 'snippet': r.snippet, 'cachedSize': r.cachedSize, 'relatedInformationPresent': r.relatedInformationPresent, 'hostName': r.hostName, 'directoryCategory': r.directoryCategory, 'directoryTitle': r.directoryTitle, 'summary': r.summary, }) return (l_meta, l_result)
Some useful suggestions and fixes from 'vegetax' on comp.lang.python """ import google import BaseHTTPServer import shutil from StringIO import StringIO # cStringIO doesn't cope with unicode import urlparse __version__ = '0.1.0' cached_types = ['txt', 'html', 'htm', 'shtml', 'shtm', 'cgi', 'pl', 'py' 'asp', 'php', 'xml'] # Any file extension that returns a text or html page will be cached google.setLicense(google.getLicense()) googlemarker = '''<i>Google is not affiliated with the authors of this page nor responsible for its content.</i></font></center></td></tr></table></td></tr></table>\n<hr>\n''' markerlen = len(googlemarker) import urllib2 # uncomment the next three lines to over ride automatic fetching of proxy settings # if you set localhost:8000 as proxy in IE urllib2 will pick up on it # you can specify an alternate proxy by passing a dictionary to ProxyHandler ##proxy_support = urllib2.ProxyHandler({}) ##opener = urllib2.build_opener(proxy_support) ##urllib2.install_opener(opener) class googleCacheHandler(BaseHTTPServer.BaseHTTPRequestHandler): server_version = "googleCache/" + __version__ cached_types = cached_types googlemarker = googlemarker
import sys, re, string, google # Set the license key (must be unique to you) google.setLicense('$YOUR_API_KEY') # Get the domain from the user try: domain = sys.argv[1] except: print("Usage: dnscour <domain.tld> \n") domain = raw_input('Enter the domain to be searched:\n') # Create the query termkeyword = "inurl:" query = keyword + domain #Start the query looppotentials = [] for i in [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]: # Perform the query five times, taking 10 results each time
def doGetCachedPage(self, url, http_proxy=None): #doGetCachedPage google.setLicense(self.license_key) return google.doGetCachedPage(url, http_proxy)
def doSpellingSuggestion(self, phrase, http_proxy=None): #doSpellingSuggestion google.setLicense(self.license_key) return google.doSpellingSuggestion(phrase, self.license_key, http_proxy)
def doGetCachedPage(self, url, http_proxy = None): google.setLicense( self.license ) return google.doGetCachedPage(url, http_proxy)
def doSpellingSuggestion(self, phrase, http_proxy = None): google.setLicense( self.license ) return google.doSpellingSuggestion(phrase, self.license, http_proxy)
def init(): google.setLicense("whatever")
def clearKeys(self): google.setLicense(None) if os.environ.get(self.envkey): del os.environ[self.envkey]
import sys, re, string, google; # Set the license key (must be unique to you) google.setLicense('$YOUR_API_KEY') # Get the domain from the user try: domain = sys.argv[1] except: print ("Usage: dnscour <domain.tld> \n") domain = raw_input('Enter the domain to be searched:\n') # Create the query termkeyword = "inurl:" query = keyword + domain #Start the query looppotentials = [] for i in [0,10,20,30,40,50,60,70,80,90]: # Perform the query five times, taking 10 results each time