Skip to content

Commit

Permalink
Allow adding search arguments to query (#110)
Browse files Browse the repository at this point in the history
still has some issue, url for no key word is not correct, will fixed it in the new release.
  • Loading branch information
emremrah authored Dec 26, 2022
1 parent 438263e commit 3fc9228
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions GoogleNews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,14 @@ def getpage(self, page=1):
def get_news(self, key="",deamplify=False):
if key != '':
key = "+".join(key.split(" "))
if self.__encode != "":
key = urllib.request.quote(key.encode(self.__encode))
self.url = 'https://news.google.com/search?q={}+when:{}&hl={}'.format(key,self.__period,self.__lang.lower())
# if period is set, add it to the query
if self.__period != "":
key += f"+when:{self.__period}"
self.url = 'https://news.google.com/search?q={}&hl={}'.format(key,self.__lang.lower())
else:
# if no query, users still can use period
if self.__period != "":
self.url += f"when:{self.__period}"
self.url = 'https://news.google.com/?hl={}'.format(self.__lang)
try:
self.req = urllib.request.Request(self.url, headers=self.headers)
Expand Down

0 comments on commit 3fc9228

Please sign in to comment.