示例#1
0
def print_top_results(query):
    """ Print a list of top hits for a query. 
    Like a mini returned first page on Google"""
    from pprint import pprint
    gs = GoogleSearch(query)
    for hit in gs.top_results():
        pprint(hit)
        print
示例#2
0
def getGoogleContent(query):
    contents=[]
    gs = GoogleSearch(query)

    for i in gs.top_results():
        contents.append(i['url'])

    return contents
示例#3
0
def print_top_results(query):
    """ Print a list of top hits for a query. 
    Like a mini returned first page on Google"""
    from pprint import pprint
    gs = GoogleSearch(query)
    for hit in gs.top_results():
        pprint(hit)
        print
示例#4
0
def print_top_results_in_spanish(query):
    """ Print a list of top hits for a query. 
    Like a mini returned first page on Google.
    Language setted in parameter hl"""
    from pprint import pprint
    gs = GoogleSearch(query, hl='es')
    for hit in gs.top_results():
        pprint(hit)
        print
def print_top_results_in_spanish(query):
    """ Print a list of top hits for a query. 
    Like a mini returned first page on Google.
    Language setted in parameter hl"""
    from pprint import pprint
    gs = GoogleSearch(query, hl='es')
    for hit in gs.top_results():
        pprint(hit)
        print
示例#6
0
 def imdb_suggest(self, query):
     excludes = [
                 #"Parents Guide", "Plot Summary", "Release Info", "Quotes", "Taglines", "FAQ", "Trivia", "News",
                 #"Full Cast", "Technical Specifications", "Goofs", "Filming Locations", "User ratings",
                 #"Critic Reviews", "Company credits", "Synopsis", "External Reviews", "Soundtracks", "Recommendations"
                ]
     google_query = ' '.join([query, ' '.join(['-"%s"' % e for e in excludes]), 'site:imdb.com/title/'])
     gs = GoogleSearch(google_query, use_proxy=False)
     suggestions = []
     for hit in gs.top_results():
         m = self.imdb_pattern.match(hit["url"])
         if m:
             suggestions.append({"id": m.group(1), "title": hit["titleNoFormatting"].replace(' - IMDb', '')})
     logging.debug("google found %d results with query: %s" % (len(suggestions), google_query))
     return suggestions
def get_google_result(query):
        '''  FUCN return {content:' ', url: ''} for google query search '''
        search_set = set()
        gs = GoogleSearch(query)
        for hit in gs.top_results():
                result = hit['titleNoFormatting']
                #pprint(result)
                if '|' in result:
                        que = hit['titleNoFormatting'].split('|')
                if '-' in result:
                        que = hit['titleNoFormatting'].split('-')
                search_set.add(que[0])
        print search_set
        for search in search_set:
                get_wiki_result(search)

        print '*'*20+'Google End'+'*'*20
示例#8
0
    def __findUrban__(self, phrase):
        # Define a list to store matches
        #
        gs = GoogleSearch(phrase + " site:urbandictionary.com")

        # Create an empty list
        #
        matches = []
        # Loop over all the results
        #
        for hit in gs.top_results():
            # Append to our list the results removeing the phrase
            # 'Urban Dictionary: ' from the result
            #
            matches.append(hit["titleNoFormatting"].replace("Urban Dictionary: ", ""))

        # return results from ubran dictionary google search
        #
        return matches
示例#9
0
    def search(self, **kwargs):

        sites = kwargs['site'] if kwargs.has_key('site') else ['imdb','tvdb', 'none']
        keys = kwargs['keys'] if kwargs.has_key('keys') else ['title', 'subtitle']

        for site in sites:

            query = self.config[site]['query']
            for key in keys:
                query = query + " " + '"' + self.data[key] + '"'

            print "[" + query + "]"

            gs = GoogleSearch(query)

            if len(gs.result_data['results']) > 0:
                for result in gs.top_results():
                    if getattr(self, '_parse_'+site+'_result')(result):
                        return
                return
示例#10
0
 def imdb_suggest(self, query):
     excludes = [
         #"Parents Guide", "Plot Summary", "Release Info", "Quotes", "Taglines", "FAQ", "Trivia", "News",
         #"Full Cast", "Technical Specifications", "Goofs", "Filming Locations", "User ratings",
         #"Critic Reviews", "Company credits", "Synopsis", "External Reviews", "Soundtracks", "Recommendations"
     ]
     google_query = ' '.join([
         query, ' '.join(['-"%s"' % e for e in excludes]),
         'site:imdb.com/title/'
     ])
     gs = GoogleSearch(google_query, use_proxy=False)
     suggestions = []
     for hit in gs.top_results():
         m = self.imdb_pattern.match(hit["url"])
         if m:
             suggestions.append({
                 "id":
                 m.group(1),
                 "title":
                 hit["titleNoFormatting"].replace(' - IMDb', '')
             })
     logging.debug("google found %d results with query: %s" %
                   (len(suggestions), google_query))
     return suggestions
示例#11
0
def SearhcGoogle(string):
    gs = GoogleSearch(string)
    for hit in gs.top_results():
        # send(hit[u'content'])
        chatvoice(hit[u'content'])
print root
#print p.xpath('//body')[0].text_content()


# GET https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=lectures
# 

# In[24]:

#Sending request to google search engine and getting results from there
from googlesearch import GoogleSearch
from pprint import pprint

gs = GoogleSearch('Neelu')
for hit in gs.top_results():
    pprint(hit)
    print


# In[23]:

#install google and pygoogle
get_ipython().system(u'pip install google')
get_ipython().system(u'pip install pygoogle')


# In[31]:

import google
#from google import gsearch
     elif (json.loads(r.text)['results']['places']['focus']['countries'] !=
           []):
         location = json.loads(
             r.text)['results']['places']['focus']['countries']
     else:
         continue
 else:
     continue
 name = location[0]['name']
 lat = location[0]['lat']
 lon = location[0]['lon']
 searchText = disasterKeyWord + " " + name + " " + date.strftime("%d %B %Y")
 #print searchText
 search = GoogleSearch(searchText)
 time.sleep(300)
 wikiTitle = search.top_results()[0]['title']
 wikiURL = search.top_results()[0]['url']
 wikiContent = search.top_results()[0]['content']
 #wikiSearchList = wikipedia.search(searchText);
 #print wikiSearchList
 # for wikiSearch in wikiSearchList:
 #     if "2016" in wikiSearch :
 #         wikiSearchWord = wikiSearch
 #         break
 #     else:
 #         wikiSearchWord = wikiSearchList[0]
 # if ( wikiSearchWord != "" ):
 #     wikiContent = wikipedia.page(wikiSearch)
 #     wikiTitle = date.strftime("%d %B %Y") + " " + wikiContent.title
 #     wikiPostConent = wikiContent.content.split('.')[0]
 #     wikiURL = wikiContent.url
示例#14
0
def top_search_results(text):
    gs = GoogleSearch(text)
    ret = []
    for hit in gs.top_results():
        ret.append((hit['title'], hit['content']))
    return ret
示例#15
0
def test_top_results_unicode():
    gs = GoogleSearch('乔治·奥斯本欣克利点')
    res = gs.top_results()
    assert any((r['url'] == 'http://www.bbc.com/zhongwen/simp/uk/2015/10/151021_analysis_uk_xi_visit_nuclear_deal' for r in res))
示例#16
0
文件: bot.py 项目: Shikib/pip3bot
def google(bot, chat_id, text):
  gs = GoogleSearch(text)
  message_str = "\n\r".join(["%s -- %s" % (gsr['url'], gsr['title']) for gsr in gs.top_results()]).replace("<b>", "").replace("</b>", "")
  bot.sendMessage(chat_id=chat_id, text=message_str)
示例#17
0
 def __findGoogle__(self, phrase):
     gs = GoogleSearch(phrase)
     matches = []
     for hit in gs.top_results():
         matches = hit["titleNoFormatting"]
     return matches
示例#18
0
def test_top_results():
    gs = GoogleSearch('george osborne hinkley point')
    res = gs.top_results()
    assert any((r['titleNoFormatting'].startswith('George Osborne presses')
                for r in res))
示例#19
0
def Google1(string):
	gs = GoogleSearch(string)
	for hit in gs.top_results():
		#send(hit[u'content'])
		chatvoice(hit[u'content'])
		break