Skip to content

Commit

Permalink
Merge pull request #46 from Iceloof/dev
Browse files Browse the repository at this point in the history
modify data range search and order by date
  • Loading branch information
HurinHu committed Jan 1, 2021
2 parents f855335 + 6c400fb commit ad3d592
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions GoogleNews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ad3d592

Please sign in to comment.