Iceloof / GoogleNews

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

googlenews.search('APPLE') #119

Closed alinemati-uwm closed 10 months ago

alinemati-uwm commented 10 months ago

Hello , when I ran this line of code

googlenews.search('APPLE')

return is

'NoneType' object is not iterable

googlenews.get_page(2) 'NoneType' object is not iterable

alinemati-uwm commented 10 months ago

MODULES

from GoogleNews import GoogleNews

METHODS

def show_routine(results): for num,page in enumerate(results): print(f"{num}. {page['date']} - {page['title']}")

MAIN

Setup the research

keywords="covid cava de' tirreni" period='10d' google_news = GoogleNews(lang='it',period=period) google=GoogleNews(lang='it',period=period)

Results from news.google.com

google_news.get_news(keywords) results_gnews=google_news.results(sort=True) show_routine(results_gnews)

Results from google.com

google.search(keywords) results_google=google.results(sort=True) show_routine(results_google)

  1. 2 giorni fa - Cava de' Tirreni, dopo tre anni d'assenza torna il Beach Volley "Città ...
  2. 5 giorni fa - Rassegna stampa: le prime pagine dei giornali salernitani del 5 agosto - Salernonotizie.it 'NoneType' object is not iterable
HurinHu commented 10 months ago

Have you tried to use

keywords="APPLE"
period='10d'
google_news = GoogleNews(period=period)
google=GoogleNews(period=period)
google_news.get_news(keywords)
results_gnews=google_news.results(sort=True)
print(results_gnews)

google.search(keywords)
results_google=google.results(sort=True)
print(results_google)
alinemati-uwm commented 10 months ago

yes, I am looking to ahve 'desc': which return None for any code.

image

for example, if I run this code

keywords="APPLE" google.search(keywords) googlenews.get_page(2) or any page the result is

image

it was working until yesterday.

Troy1818 commented 10 months ago

Hello, I've also been encountering this issue for the last 12 hours. Prior to that the google.search(keyword) portion of the code was working wonderfully. However, now it outputs 'NoneType' object is not iterable. I've noticed the google_news.get_news(keywords) option still runs properly. Any other ideas on how to get google.search to not return a NoneType object?

HurinHu commented 10 months ago

It seems google change its web page source code recently, I will fixed it ASAP if I have time, or if some else fix it, can merge into this project.

alinemati-uwm commented 10 months ago

let me see if I can fix your code. I will keep you post it.

by the way, when I ran below code, it includes the desc. it might help. it is working now. @HurinHu

from GoogleNews import GoogleNews
googlenews = GoogleNews()
googlenews.clear()
import pandas as pd

googlenews = GoogleNews(lang='en')
googlenews.get_news('india road accident')
googlenews.search('india road accident')

result_0 = googlenews.page_at(1)

desc_1 = googlenews.get_texts()
link_1 = googlenews.get_links()
link = googlenews.get_links()

for i in list(range(2, 5)):

    result = googlenews.page_at(i)
    desc = googlenews.get_texts()
    link = googlenews.get_links()

    desc_1 = desc_1 + desc
    link_1 = link_1 + link

... rest of code convert to pandas
...

image

Troy1818 commented 10 months ago

Hello again, I wanted to follow up to see if anyone has resolved the issue? I still received the same 'NoneType' object output this morning. I could also make an attempt at updating it over the weekend if others haven't been able to work on it. Thank you!

alinemati-uwm commented 10 months ago

Not yet. I am try to later.

HurinHu commented 10 months ago

New release v1.6.9 solved this issue, but .total_count() is not working with .search() anymore.

alinemati-uwm commented 10 months ago

thanks for update, I can see two bugs there

I search for chatgot to check

  1. URL looks extra stuff which does not open the link
  2. 'desc': '' is empty

Mycode: from GoogleNews import GoogleNews googlenews = GoogleNews() googlenews.enableException(True) googlenews.set_lang('en') googlenews.set_period('1d') googlenews.set_time_range('08/11/2023','02/28/2020') googlenews.set_encode('utf-8') googlenews.search('Chatgpt') result = googlenews.page_at(2) result

My result: [{'title': 'Hackers take on ChatGPT with support from White House', 'media': 'CNN', 'date': '6 hours ago', 'datetime': datetime.datetime(2023, 8, 11, 20, 8, 33, 681797), 'desc': '', 'link': '/url?esrc=s&q=&rct=j&sa=U&url=https://www.cnn.com/videos/world/2023/08/11/exp-hackers-ai-vegas-lkl-081102pseg2-cnni-world.cnn&ved=2ahUKEwi11JzzhNaAAxUxm1YBHTz2Dx04ChDF9AF6BAgDEAI&usg=AOvVaw14nsFJTPwZeSPlNUzqrOE5', 'img': 'data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='},