From 10e5b9488ce273a8f639b3031dae4e8c8f9f9f12 Mon Sep 17 00:00:00 2001 From: emremrah Date: Sun, 25 Dec 2022 13:03:11 +0300 Subject: [PATCH] Allow adding search arguments to query --- GoogleNews/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/GoogleNews/__init__.py b/GoogleNews/__init__.py index 5cdf385..e9a2700 100644 --- a/GoogleNews/__init__.py +++ b/GoogleNews/__init__.py @@ -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)