Python google.search() Examples

The following are 14 code examples for showing how to use google.search(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module google , or try the search function .

Example 1
Project: dl4ir-webnav   Author: nyu-dl   File: google_search.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_candidates(qatp):

    wk = wiki.Wiki(prm.pages_path)
    titles_pos = wk.get_titles_pos()

    candidates = []
    n = 0
    for q,a,t,p in qatp:
        if n % 100 == 0:
            print 'finding candidates sample', n
        n+=1

        c = []

        for page in google.search(q.lower() + ' site:wikipedia.org', num=prm.max_candidates,stop=prm.max_candidates, pause=45):
            title = page.replace('https://en.wikipedia.org/wiki/','').replace('_',' ').lower()
            if title in titles_pos:
                c.append(titles_pos(title))

        candidates.append(c)
        
    return candidates 
Example 2
Project: Vaile   Author: VainlyStrain   File: pastebin.py    License: GNU General Public License v3.0 6 votes vote down vote up
def getposts(web):
    web0 = web
    if "@" in web0:
        web0 = web0.split("@")[1]
    site = str(web0)
    def clear_cookie():
        fo = open(".google-cookie", "w")
        fo.close()


    def google_it (dork):
        clear_cookie()
        for title in search(dork, stop=30):
            print(B+' [!] Post Found :> '+C+title)
            time.sleep(0.5)

    try:
        print(C+" [*] Finding Pastebin posts ...\n")
        google_it("site:pastebin.com intext:"+site+"")

    except urllib.error.HTTPError as err:
        if err.code == 503:
            print(R+' [-] Captcha appeared...\n')
            pass 
Example 3
Project: Vaile   Author: VainlyStrain   File: googleSearch.py    License: GNU General Public License v3.0 6 votes vote down vote up
def googleSearch():

    try:
        time.sleep(0.4)
        #print(R+'\n   ===========================')
        print(R+'\n    G O O G L E   S E A R C H')
        print(R+'   ––·‹›·––·‹›·––·‹›·––·‹›·––·\n')
                    
        lol = input(O+ " [§] QUERY :> " + color.END)
        time.sleep(0.8)
        m = input(C+' [§] Search limit (not recommended above 30) :> ')
        print(C+ " [!] Below are the list of websites with info on '" +lol+ "'")
        x = search(lol, tld='com', lang='es', stop=int(m))
        for url in x:
            print(O+"   [!] Site Found :>"+C+color.TR3+C+G + url+C+color.TR2+C)
            q = open('.google-cookie','w')
            q.close()
    except urllib.error.HTTPError:
        print(R+' [-] You have used google many times.')
        print(R+' [-] Service temporarily unavailable.') 
Example 4
Project: W.I.L.L   Author: ironman5366   File: search.py    License: MIT License 6 votes vote down vote up
def is_search(event):
    '''Determine whether it's a search command'''
    command = event["command"]
    if "search" in event["verbs"]:
        return True
    question_words = [
        "what",
        "when",
        "why",
        "how",
        "who",
        "are",
        "is"
    ]
    first_word = command.split(" ")[0].lower()
    log.debug("First word in command is {0}".format(first_word))
    if first_word in question_words:
        return True
    return False 
Example 5
Project: W.I.L.L   Author: ironman5366   File: search.py    License: MIT License 6 votes vote down vote up
def main(data):
    '''Start the search'''
    response = {"text": None, "data":{}, "type": "success"}
    query = data["command"]
    log.info("In main search function with query {0}".format(query))
    db = data["db"]
    answer = False
    wolfram_key = tools.load_key("wolfram", db)
    wolfram_response = search_wolfram(query, wolfram_key)
    # If it found an answer answer will be set to that, if not it'll still be false
    answer = wolfram_response
    if answer:
        response["text"] = answer
    else:
        response["text"]=search_google(query)
    return response 
Example 6
Project: Vaile   Author: VainlyStrain   File: linkedin.py    License: GNU General Public License v3.0 5 votes vote down vote up
def getposts(web):
    web0 = web
    if "@" in web0:
        web0 = web0.split("@")[1]
    site = str(web0)
    def clear_cookie():
        fo = open(".google-cookie", "w")
        fo.close()


    def google_it (dork):
        clear_cookie()
        for title in search(dork, stop=30):
            print(B+' [!] Profile Found :> '+C+title)
            time.sleep(0.5)

    try:
        print(GR+" [*] Finding LinkedIn Employees ...\n")
        google_it("site:linkedin.com employees "+site+"")
        print(O+' [!] Pausing to avoid captcha...'+C)
        time.sleep(10)

        print(GR+' [*] Finding Linkedin company profiles...\n')
        google_it("site:linkedin.com comapany "+site+"")

    except urllib.error.HTTPError as err:
        if err.code == 503:
            print(R+' [-] Captcha appeared...\n')
            pass 
Example 7
Project: SML-Cogs   Author: smlbiobot   File: search.py    License: MIT License 5 votes vote down vote up
def setsearch(self, ctx: Context):
        """Set search settings."""
        if ctx.invoked_subcommand is None:
            await send_cmd_help(ctx) 
Example 8
Project: SML-Cogs   Author: smlbiobot   File: search.py    License: MIT License 5 votes vote down vote up
def search(self, ctx: Context):
        """Google."""
        if ctx.invoked_subcommand is None:
            await send_cmd_help(ctx) 
Example 9
Project: SML-Cogs   Author: smlbiobot   File: search.py    License: MIT License 5 votes vote down vote up
def search_google(
            self, ctx: Context, search_str: str, lang='english', stop=1):
        """Google search and return URL results."""
        out = []
        await self.bot.send_typing(ctx.message.channel)
        for url in google.search(search_str, num=5, stop=stop):
            await self.bot.send_typing(ctx.message.channel)
            async with aiohttp.get(url) as response:
                soup = BeautifulSoup(await response.text(), "html.parser")
                out.append(soup.title.string)
            out.append("<{}>\n".format(url))
            # out.append(gout)
        for page in pagify('\n'.join(out)):
            await self.bot.say(page) 
Example 10
Project: SML-Cogs   Author: smlbiobot   File: search.py    License: MIT License 5 votes vote down vote up
def search_google_images(
            self, ctx: Context, search_str: str, stop=1):
        """Google search images."""
        out = []
        await self.bot.send_typing(ctx.message.channel)
        for url in google.search_images(search_str, num=5, stop=stop):
            await self.bot.send_typing(ctx.message.channel)
            async with aiohttp.get(url) as response:
                soup = BeautifulSoup(await response.text(), "html.parser")
                out.append(soup.title.string)
            out.append("<{}>\n".format(url))
            # out.append(gout)
        for page in pagify('\n'.join(out)):
            await self.bot.say(page) 
Example 11
Project: SML-Cogs   Author: smlbiobot   File: search.py    License: MIT License 5 votes vote down vote up
def search_imgur(self, ctx: Context, *, query: str):
        """Imgur search."""
        search_id = 0

        await self.bot.send_typing(ctx.message.channel)

        try:
            client_id = self.settings["imgur"]["id"]
            client_secret = self.settings["imgur"]["secret"]
        except KeyError:
            await self.bot.say("Please set imgur id and secret.")
            return

        try:
            search_id = self.settings["imgur"]["search_id"]
        except KeyError:
            self.settings["imgur"]["search_id"] = 0

        # count = 0
        client = ImgurClient(client_id, client_secret)
        results = client.gallery_search(query)

        try:
            result = next(islice(results, search_id, None))
            if result.is_album:
                img = client.get_image(result.cover)
            else:
                img = result
            await self.bot.say(str(img.link))
            search_id += 1
        except StopIteration:
            search_id = 0

        self.settings["imgur"]["search_id"] = search_id
        dataIO.save_json(JSON, self.settings) 
Example 12
Project: IPTV   Author: Pirate-Crew   File: Crawler.py    License: MIT License 5 votes vote down vote up
def search_links(self):
        """Print the first 30 links from a Web search

        We set the limit of 30 links because this script serve as demonstration and it's
        not intended to be use for personal purpose.
        """
        for url in google.search(self.searchString, num=30, stop=1):
            parsed = urlparse(url)
            self.parsedUrls.append(parsed.scheme + "://" + parsed.netloc) 
Example 13
Project: AutOSINT   Author: bharshbarger   File: googledork.py    License: MIT License 4 votes vote down vote up
def run(self, args, lookup, reportDir):

        self.args = args

        #C58EA28C-18C0-4a97-9AF2-036E93DDAFB3 is string for open OWA attachments, for example
        #init lists

        #iterate the lookup list
        for i, l in enumerate(lookup):
            for d in self.args.dorks:

                #add header to result
                self.google_result.append('[i] Google query for: "%s site:%s"' % (str(d),str(l)))

                #open a file for each domain searched
                googleFile=open(reportDir+l+'/'+l+'_google_dork.txt','w')

                #show user whiat is being searched
                print ('[+] Google query %s for %s site:%s' % (str(i + 1),str(d),str(l)))
                print('[+] Results:')
                
                try:
                    #iterate url results from search of password(for now) and site:current list value
                    for url in search(str(self.args.dorks)+' site:'+str(l), stop = 20):
                        #append results together
                        self.google_result.append(url)

                        #rate limit with 2 second delay
                        time.sleep(2)
                #catch exceptions
                except Exception as e:
                    print ('[!] Error encountered: %s' % e)
                    pass
        #iterate results
        for r in self.google_result:
            #write results on newlines
            googleFile.writelines(r + '\r\n')

        #verbosity flag
        if self.args.verbose is True:
            for r in self.google_result: print (''.join(r))
                
        #return results list
        return self.google_result 
Example 14
Project: W.I.L.L   Author: ironman5366   File: search.py    License: MIT License 4 votes vote down vote up
def search_google(query):
    '''Search google and determine if wikipedia is in it'''
    search_object = google.search(query)
    #Determine if a wikipedia url is in the first 5 searches
    urls = []
    for i in range(0, 4):
        url = search_object.__next__()
        urls.append(url)
        if "wikipedia.org/wiki" in url:
            wikipedia_search = wikipedia.search(query)[0]
            url = wikipedia.page(wikipedia_search).url
            response = wikipedia.summary(wikipedia_search) + " ({0})".format(url)
            return response
    #If there were no wikipedia pages
    first_url = urls[0]
    try:
        article = Article(first_url)
        article.download()
        article.parse()
        article.nlp()
        article_summary = article.summary
        article_title = article.title
        return "{0}\n{1} - ({2})".format(
            article_summary, article_title, first_url
        )

    except Exception as article_exception:
        try:
            log.debug("Got error {0}, {1} while using newspaper, switching to bs4".format(
            article_exception.message,article_exception.args
            ))
            html = requests.get(first_url).text
            #Parse the html using bs4
            soup = BeautifulSoup(html, "html.parser")
            [s.extract() for s in soup(['style', 'script', '[document]', 'head', 'title'])]
            text = soup.getText()
         # break into lines and remove leading and trailing space on each
            lines = (line.strip() for line in text.splitlines())
            # break multi-headlines into a line each
            chunks = (phrase.strip() for line in lines for phrase in line.split("  "))
            # drop blank lines
            soup_text = '\n'.join(chunk for chunk in chunks if " " in chunk)
            response = format(soup_text) + " ({0})".format(first_url)
            return response
        except Exception as search_exception:
            log.info("Error {0},{1} occurred while searching query {2}".format(
                search_exception.message, search_exception.args, query
            ))
            return "Error encountered on query {0}".format(query)