Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding search arguments to query #110

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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