Iceloof / GoogleNews

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

Multiple search terms #27

Closed avanpal closed 4 years ago

avanpal commented 4 years ago

Hi,

I'm trying to web search multiple terms using GoolgeNews. My script used to work on older versions of GoolgeNews but it no longer works. It only searches the first term multiple times, and gives me repeating results.

Any helps is greatly appreciated. I need this fix by Wednesday for work.

from GoogleNews import GoogleNews import sys f = open("googlenews22.txt", "w") keywordlist = ['apple', 'samsung', 'nokia'] googlenews = GoogleNews() for word in keywordlist: googlenews.search(word) googlenews.setTimeRange('15/05/2020','15/06/2020') googlenews.getpage(1) results = googlenews.result() listofres = [] for ting in word: title = ting['title'] date = ting['date'] link = ting['link'] listofres += [[title, date, link]] f.write("%s, %s, %s \n" %(title, date, link))

HurinHu commented 4 years ago

I think we never have supported keyword list, every time you use googlenews.search() will clean the previous result, the only way you can do is to search 'apple samsung nokia' as keyword

avanpal commented 4 years ago

Thank you for your reply. Is there anyway I can search each term and get the first page results for each term. I.e. Search results for 'apple', search results for 'Samsung' etc. I have a list of 100 search terms which is why I'm trying to find an easy solution to search each term. I was able to use the above code before but it no longer seems to work

HurinHu commented 4 years ago

You can do it in for loop, results = googlenews.result() only get one query result, you need to save results and combine into one at the end, but I don't suggest to do that, unless you set sleep time to pause it for a while, otherwise Google may block you.