Iceloof / GoogleNews

Script for GoogleNews
https://pypi.org/project/GoogleNews/
MIT License
314 stars 88 forks source link

get_news returns None all the time #79

Closed leorrose closed 2 years ago

leorrose commented 2 years ago

Problem: When trying to get news using the get_news method it returns None all the time.

Screenshot: image

Code for reproduce:

from GoogleNews import GoogleNews
googlenews = GoogleNews()
print(googlenews.get_news('APPLE'))
print(googlenews.get_news('Facebook'))
print(googlenews.get_news('Tesla'))

OS: windows 10

Python version: 3.8.7

HurinHu commented 2 years ago

you should write in this way

from GoogleNews import GoogleNews
googlenews = GoogleNews()
googlenews.get_news('APPLE')
results = googlenews.results()
print(results)

This you should use googlenews.results() to get the result, googlenews.get_news('APPLE') is not returned dataset, and it is only getting first page, if you want to get more than one page, you need to do like this,

from GoogleNews import GoogleNews
googlenews = GoogleNews()
googlenews.get_news('APPLE')
googlenews.get_page(2)
googlenews.get_page(3)
results = googlenews.results()
print(results)

If you only want to get specific page,

result = googlenews.page_at(2)