Iceloof / GoogleNews

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

GoogleNews search is not working, please help #124

Closed SamratDey112358 closed 10 months ago

SamratDey112358 commented 10 months ago

googlenews.search("<any keyword") is giving "'NoneType' object is not iterable" in Python

HurinHu commented 10 months ago

Are you using the latest version? I can see both .get_news() and .search() can return a list of result with latest version

SamratDey112358 commented 10 months ago

Hi, am using version 1.6.9, just upgraded it

HurinHu commented 10 months ago

Try to use browser to open google and search something with same pc, and check whether Google does robot verification or not. This may be Google recognize your behaviour as robot and do extra verification, then will cause this issue. Otherwise it seems not code issue.

SamratDey112358 commented 10 months ago

No I am not getting any message about Google doing robot verification, can search as usual on browser also same issue in multiple systems have also tried with different internet connections

HurinHu commented 10 months ago
user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0'
headers = {'User-Agent': user_agent}
url='https://www.google.com/search?q=%3Cany%20keyword&lr=lang_en&biw=1920&bih=976&source=lnt&tbs=lr:lang_1en,qdr:10d,,sbd:1&tbm=nws&start=0'
req = urllib.request.Request(url.replace("search?","search?hl="+self.__lang+"&gl="+self.__lang+"&"), headers=headers)
response = urllib.request.urlopen(req)
page = response.read()

Try this code and see whether you can get the details

SamratDey112358 commented 10 months ago

"self" is not defined, can I change it to "en"?

HurinHu commented 10 months ago

"self" is not defined, can I change it to "en"?

yes, just set your language

SamratDey112358 commented 10 months ago

it ran, there is an output for page which is a huge chunk of string like this "b'<!doctype html><any keyword - Google Search Githubissues.

  • Githubissues is a development platform for aggregating issues.