Iceloof / GoogleNews

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

Results return links to articles in "news.google.com/./articles/XYZ" format not direct links. #71

Closed SpicyParsnip closed 2 years ago

SpicyParsnip commented 2 years ago

Is there a way to get direct links to the news stories rather than links no 'news.google.com/.articles/asjlskjdlkadoi'?

I've seen guides to using this python library and they seem to get the direct URL in the results (like http:\bbc.co.uk...)

Is there a way to resolve this?...

I understand a bit more about this now, they are re-direct links.

It would be nice if you could add a few lines of code in the guide showing how you could re-solve these.

I understand resolving them would result is slowing down the program as you have to perform http requests.

I'm currently googling for some code which works to do this.

HurinHu commented 2 years ago

You can try to get the real link with some code like this

import requests
res=requests.get('https://news.google.com/.articles/asjlskjdlkadoi'')
res.url

Google is not provided API officially, and this library is only fetching the original content from the google news search, so if you want to get the direct url or other details, you might need to do some extra process, which might slow it down, and if calling google frequently, google server might recognize your program as robot and block your IP. So if you have to do this, just put some random delay time between each request, it might help you avoid this.