Skip to content

Commit

Permalink
Merge branch 'master' of angryrancor/xgoogle
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Jul 25, 2016
2 parents 45f7a5f + dd29c80 commit e61e2c4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
9 changes: 6 additions & 3 deletions examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
gs.results_per_page = 50
results = gs.get_results()
for res in results:
print res.title.encode('utf8')
print res.desc.encode('utf8')
print res.url.encode('utf8')
if res.title is not None:
print res.title.encode('utf8')
if res.desc is not None:
print res.desc.encode('utf8')
if res.url is not None:
print res.url.encode('utf8')
print
except SearchError, e:
print "Search failed: %s" % e
Expand Down
34 changes: 34 additions & 0 deletions examples/example4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/python
#
# Justin Vieira ([email protected])
# http://www.rancorsoft.com -- Let's Rock Together.
#
# This program does a Google search for "super test results" and returns
# all results.
#

from xgoogle.search import GoogleSearch, SearchError
from threading import Thread
from random import randint
import time

try:
gs = GoogleSearch("super test results")
gs.results_per_page = 50
displayedResults = 0
results = gs.get_results()
while displayedResults < gs.num_results:
for res in results:
if res.title is not None:
print res.title.encode('utf8')
if res.desc is not None:
print res.desc.encode('utf8')
if res.url is not None:
print res.url.encode('utf8')
displayedResults += gs.results_per_page
print
time.sleep(randint(15,60))
results = gs.get_results()
except SearchError, e:
print "Search failed: %s" % e

4 changes: 2 additions & 2 deletions xgoogle/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GoogleSearch(object):
SEARCH_URL_1 = "http://www.google.%(tld)s/search?hl=%(lang)s&q=%(query)s&num=%(num)d&btnG=Google+Search"
NEXT_PAGE_1 = "http://www.google.%(tld)s/search?hl=%(lang)s&q=%(query)s&num=%(num)d&start=%(start)d"

def __init__(self, query, random_agent=False, debug=False, lang="en", tld="com", re_search_strings=None, repeat=None):
def __init__(self, query, random_agent=True, debug=False, lang="en", tld="com", re_search_strings=None, repeat=None):
self.query = query
self.debug = debug
self.browser = Browser(debug=debug)
Expand Down Expand Up @@ -294,7 +294,7 @@ def _extract_result(self, result):
"""Extract title,url,desc for a result"""
title, url = self._extract_title_url(result)
desc = self._extract_description(result)
if not title or not url:
if not title and not url:
return None
return SearchResult(title, url, desc)

Expand Down

0 comments on commit e61e2c4

Please sign in to comment.