diff --git a/GoogleNews/__init__.py b/GoogleNews/__init__.py index 70b740a..08af7c2 100644 --- a/GoogleNews/__init__.py +++ b/GoogleNews/__init__.py @@ -94,11 +94,11 @@ def get_page(self, page=1): """ try: if self.__start != "" and self.__end != "": - self.url = "https://www.google.com/search?q={}&lr=lang_{}&tbs=lr:lang_1{},cdr:1,cd_min:{},cd_max:{}&tbm=nws&start={}".format(self.__key,self.__lang,self.__lang,self.__start,self.__end,(10 * (page - 1))) + self.url = "https://www.google.com/search?q={}&lr=lang_{}&biw=1920&bih=976&source=lnt&&tbs=lr:lang_1{},cdr:1,cd_min:{},cd_max:{},sbd:1&tbm=nws&start={}".format(self.__key,self.__lang,self.__lang,self.__start,self.__end,(10 * (page - 1))) elif self.__period != "": - self.url = "https://www.google.com/search?q={}&lr=lang_{}&tbs=lr:lang_1{},qdr:{},&tbm=nws&start={}".format(self.__key,self.__lang,self.__lang,self.__period,(10 * (page - 1))) + self.url = "https://www.google.com/search?q={}&lr=lang_{}&biw=1920&bih=976&source=lnt&&tbs=lr:lang_1{},qdr:{},,sbd:1&tbm=nws&start={}".format(self.__key,self.__lang,self.__lang,self.__period,(10 * (page - 1))) else: - self.url = "https://www.google.com/search?q={}&lr=lang_{}&tbs=lr:lang_1{}&tbm=nws&start={}".format(self.__key,self.__lang,self.__lang,(10 * (page - 1))) + self.url = "https://www.google.com/search?q={}&lr=lang_{}&biw=1920&bih=976&source=lnt&&tbs=lr:lang_1{},sbd:1&tbm=nws&start={}".format(self.__key,self.__lang,self.__lang,(10 * (page - 1))) except AttributeError: raise AttributeError("You need to run a search() before using get_page().") try: diff --git a/README.md b/README.md index 221624e..8aefe6d 100755 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ googlenews.get_news('APPLE') googlenews.search('APPLE') ``` -Default return first page result. To get other page of search results: +Default return first page result, you don't need to get first page again, otherwise you might get duplicate result. To get other page of search results: ``` googlenews.get_page(2) @@ -82,3 +82,7 @@ googlenews.clear() ``` ## Issue Image is not working in the latest version, it can only return default google loading gif + +The date range is not always working as Google may return the result with random order or out of date range. + +Google may recognize the program as automated robots and block the IP, using cloud server and fetching data with high frequency will get higher chance to be blocked. diff --git a/setup.py b/setup.py index 20060e0..fa82ad7 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="GoogleNews", - version="1.5.1", + version="1.5.2", author="Hurin Hu", author_email="hurin@live.ca", description="Google News search for Python", diff --git a/test/test_search.py b/test/test_search.py index 85066a5..24e2c73 100644 --- a/test/test_search.py +++ b/test/test_search.py @@ -26,7 +26,7 @@ def testResultNumberWithTwoPages(self): print('Result length with two pages is correct') def testEncode(self): - googlenews = GoogleNews(encode='utf-8') + googlenews = GoogleNews(lang='ru',encode='utf-8') googlenews.search("Моцарт") length = len(googlenews.result()) self.assertNotEqual(length, 0)