本文整理汇总了Python中xgoogle.search.GoogleSearch类的典型用法代码示例。如果您正苦于以下问题:Python GoogleSearch类的具体用法?Python GoogleSearch怎么用?Python GoogleSearch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GoogleSearch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getGooogleResults
def getGooogleResults(query, exclude):
try:
print "Searching for {0} but excluding these {1}".format(query, exclude)
page = 1
gs = GoogleSearch(query)
gs.results_per_page = 100
results = gs.get_results()
示例2: getUrls2
def getUrls2( page_num ):
gs = GoogleSearch('shareholder letter')
gs.results_per_page = 50
gs.page = page_num
results = gs.get_results()
for item in results:
print item.url.encode("utf8")
示例3: google
def google(termtosearch, action):
#action = spam or phis
try:
gs = GoogleSearch(termtosearch)
gs.results_per_page = 100
results = []
while True:
tmp = gs.get_results()
if not tmp:
break
results.extend(tmp)
#TODO switch in this code block
if action == 'mal':
for res in results:
checkAgainstGoogle(res.url.encode('utf8'))
else:
if action == 'spam':
for res in results:
print '\033[1;34mLooking for SPAM in ......%s\033[1;m' % (res.url.encode('utf8'))
spam_detect(res.url.encode('utf8'))
elif action == 'phis':
for res in results:
print '\033[1;34mLooking for PHISHING in ......%s\033[1;m' % (res.url.encode('utf8'))
phishing_detect(res.url.encode('utf8'))
else:
for res in results:
print res.url.encode('utf8')
except SearchError, e:
print "Search failed: %s" % e
示例4: google
def google(data): #In this fuction we will do the phrasing of the subject line ourselfs.
print "Called google"
tore = ''
search_string = ''
if data[1] == 'search':
for i in range(2,len(data)):
search_string = search_string + data[i] + ' '
try:
tore = "Here are the first 25 results from google when \'"+search_string+"\' is queried\n\n"
gs = GoogleSearch(search_string)
gs.results_per_page = 25
results = gs.get_results()
for res in results:
#print res.title.encode('utf8')
tore = tore+res.title.encode('utf8')+"\n"
#print res.desc.encode('utf8')
tore = tore+res.desc.encode('utf8')+"\n"
#print res.url.encode('utf8')
tore = tore+res.url.encode('utf8')+"\n\n--------------------------------------\n"
print
except:
print "Search failed: %s" % e
tore = "Search failed: %s" % e
return tore
示例5: google
def google(self,text):
try:
print "Trying to search for "+text
g1 = GoogleSearch(text)
g1.results_per_page = 25
results = g1.get_results()
if len(results)==0:
print "No search result!!"
else:
print "Results FOund!!"
print type(results)
print len(results)
for res in results[:2]:
time.sleep(1)
url = res.url.encode("utf8")
response = self.search(url)
if response == "Kgpian":
self.close()
break
except SearchError, e:
print "Failed Once"
示例6: getGoogleResults
def getGoogleResults(self,pluginname,latest,cve):
try:
gs = GoogleSearch("inurl:'wp-content/plugins/" + pluginname + "'", random_agent=True)
gs.results_per_page = 100
numberOfprocessed = 0
self.all_run = []
for i in range(int(limitForSearch)):
results = gs.get_results()
if not results:
break
# Semaphore for write in order to screen
self.checkSimultaneus = threading.Semaphore(int(NumThreats))
# Semaphore for write to file
self.writeFile = threading.Semaphore(int(NumThreats)-1)
for res in results:
self.checkSimultaneus.acquire()
host_name = urlparse(res.url.encode()).hostname
# Create thread
t = threading.Thread(target=self.__getGoogleResults, args=(host_name,latest,pluginname,cve))
self.all_run.append(t)
# run thread
self.all_run[len(self.all_run)-1].start()
except SearchError, e:
print "Search failed: %s" % e
示例7: collect
def collect(self):
gs = GoogleSearch("site:"+self.target)
while True:
results = gs.get_results()
for res in results:
self.urls.append(res.url)
if len(results)<10:
break
示例8: go
def go(self, query, pages):
search = GoogleSearch(query)
search.results_per_page = 10
for i in range(pages):
search.page = i
results = search.get_results()
for page in results:
self.scrape(page)
示例9: update_from_web
def update_from_web( model, film, year ):
search = "kinopoisk.ru " + year + " " + film
print "Search: %s" % search
browser=Browser(debug=True)
gs = GoogleSearch(search)
gs.results_per_page = 1
results = gs.get_results()
try:
for res in results:
pageurl = res.url.encode('utf8')
page = browser.get_page( pageurl )
soup = BeautifulStoneSoup( page[ page.find("<html"):], convertEntities=BeautifulStoneSoup.HTML_ENTITIES, fromEncoding="windows-1251" )
print "URL: %s" % pageurl
rating = soup.find('a',attrs={'class':'continue'})
if rating:
r = strip(rating).split(' ')
try:
model.rating = float( r[1] )
print "Rating: %s" % r[1]
except Exception, ex:
model.rating = 0.0
print "Can't parse rating"
title = soup.find('h1','moviename-big')
if title:
print "Title: %s" % strip(title)
model.title = strip(title)
info = soup.find('span','_reachbanner_')
if info:
print "Info: %s" % strip(info)
model.description = strip( info )
img = soup.find('img', attrs={"width" : "120"})
if img:
print "Image: %s" % img['src']
model.image = "http://www.kinopoisk.ru%s" % img['src']
#getTrailer("t26538","397494/kinopoisk.ru-District-9-36971.mp4","397494/1_36971.jpg","480","270","tr","","");
import re
m = re.search("getTrailer\((.*)\)",str(soup))
if not m:
pass
else:
parts = m.group(1).split('"')
url = "http://tr.kinopoisk.ru/%s" % parts[3]
model.trailer = url
image = "http://tr.kinopoisk.ru/%s" % parts[5]
model.trailer_image = image
print "Trailer: %s" % url
print "TrailerImage: %s" % image
break
except Exception,e:
print "WARNING: %s" % e
示例10: startSearch
def startSearch(self, domain="", target_keywords=[]):
gs = GoogleSearch(target_keyword)
gs.results_per_page = 100
results = gs.get_results()
for idx, res in enumerate(results):
parsed = urlparse(res.url)
domain = self.__makeUrl(parsed.netloc)
if domain == target_domain:
print "Ranking position %d for keyword %s on domain %s" % (idx + 1, target_keyword, target_domain)
示例11: searchPage
def searchPage(textToSearch, page):
items = []
gs = GoogleSearch(textToSearch)
gs.results_per_page = 100
gs.page = page
results = gs.get_results()
for res in results:
url = res.url.encode('utf8')
items.append(url);
return items
示例12: get_number_of_results
def get_number_of_results(term, ajax=False, verbose=True):
if not ajax:
gs = GoogleSearch(term)
page = str(gs._get_results_page())
match = reg.search(page)
if match:
if verbose: print(term, match.groups()[0])
return int(match.groups()[0].replace(',',''))
else:
raw_input((term, page))
return int(search(term)['responseData']['cursor']['estimatedResultCount'])
示例13: main
def main():
#the hardcoded search query:
gs = GoogleSearch("computer")
gs.result_per_page=10
results = gs.get_results()
for r in results:
Crow(r.url).select("a").to(SqlitePipeline()).async_start(50)
Crow.run()
f.close()
示例14: get_results
def get_results(query):
gs = GoogleSearch(query);
gs.results_per_page = 9001;
results = gs.get_results();
ret = [];
for idx, res in enumerate(results):
domain = mk_nice_domain(res.url);
domain = domain.replace("pastebin.com/", "pastebin.com/raw.php?i=");
print 'Found codes at %s' % domain;
ret.append(domain);
return ret;
示例15: search_google
def search_google(term, domain):
try:
log.debug('Performing Google search for "{}"'.format(term))
gs = GoogleSearch(term, tld=domain)
gs.results_per_page = 10
results = gs.get_results()
log.debug('Got {} results'.format(len(results)))
return [Url(res.url) for res in results[:10]]
except SearchError as exc:
log.exception(exc)
return None