Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change li to div and connection #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions xgoogle/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ def __init__(self, user_agent=BROWSERS[0], debug=False, use_pool=False):
self.debug = debug

def get_page(self, url, data=None):
handlers = [PoolHTTPHandler]
opener = urllib2.build_opener(*handlers)
if data: data = urllib.urlencode(data)
request = urllib2.Request(url, data, self.headers)
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]

try:
response = opener.open(request)
response = opener.open(url)
return response.read()
except (urllib2.HTTPError, urllib2.URLError), e:
raise BrowserError(url, str(e))
Expand Down
6 changes: 3 additions & 3 deletions xgoogle/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def _get_results_page(self):
page = self.browser.get_page(safe_url)
except BrowserError, e:
raise SearchError, "Failed getting %s: %s" % (e.url, e.error)

return BeautifulSoup(page)

def _extract_info(self, soup):
Expand All @@ -226,7 +225,7 @@ def _extract_info(self, soup):
return {'from': int(matches.group(1)), 'to': int(matches.group(2)), 'total': int(matches.group(3))}

def _extract_results(self, soup):
results = soup.findAll('li', {'class': 'g'})
results = soup.findAll('div', {'class': 'g'})
ret_res = []
for result in results:
eres = self._extract_result(result)
Expand All @@ -237,7 +236,8 @@ def _extract_results(self, soup):
def _extract_result(self, result):
title, url = self._extract_title_url(result)
desc = self._extract_description(result)
if not title or not url or not desc:
desc = desc is None and desc or ""
if not title or not url :
return None
return SearchResult(title, url, desc)

Expand Down