diff --git a/.travis.yml b/.travis.yml index ef54575..8b6f0d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: python python: - "2.7" + - "3.2" - "3.6" +# 3.2 added because https://github.com/aviaryan/python-gsearch/issues/3 # command to run tests script: python -m unittest tests.tests diff --git a/gsearch/googlesearch.py b/gsearch/googlesearch.py index 871ba62..c60673f 100644 --- a/gsearch/googlesearch.py +++ b/gsearch/googlesearch.py @@ -11,13 +11,16 @@ # Python 3 from urllib import request from html.parser import HTMLParser # keep it to avoid warning - from html import unescape from urllib.parse import quote, unquote # local try: from gsearch.data import user_agents # works in tests except ImportError: from data import user_agents # works in a normal run + try: + from html import unescape # Python 3.4+ + except ImportError: + pass except ImportError: # Python 2 import urllib2 as request @@ -86,7 +89,12 @@ def convert_unicode(text): h = HTMLParser() s = h.unescape(text) else: - s = unescape(text) + try: + s = unescape(text) + except Exception: + # Python 3.3 and below + # https://stackoverflow.com/a/2360639/2295672 + s = HTMLParser().unescape(text) return s diff --git a/tests/tests.py b/tests/tests.py index 9da75c1..0138031 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -17,7 +17,7 @@ def test_results_count(self): self.assertTrue(len(res) > 10, 'Less than 11 results returned') def test_results_zero(self): - res = search('dsjaksfajsdhkhawkehkajdwek') + res = search('dsjaksfajsdhkhawkehkajdwek' + (str(randint(10,100)) * 5)) self.assertTrue(len(res) == 0, 'There was a result. What has this world come to?') def test_unicode(self):