Skip to content

Instantly share code, notes, and snippets.

@DATAUNIRIO
Created November 8, 2021 23:14
Show Gist options
  • Save DATAUNIRIO/589b9dad95c38704dd874709d475d2aa to your computer and use it in GitHub Desktop.
Save DATAUNIRIO/589b9dad95c38704dd874709d475d2aa to your computer and use it in GitHub Desktop.
get_googlenews_with_python.py
import os
os.getcwd()
os.chdir('/home/steven/Documentos/diretorio_py')
#--------------------------------------------------------------------------
from GoogleNews import GoogleNews
import pandas as pd
from time import strftime
#--------------------------------------------------------------------------
googlenews = GoogleNews()
googlenews = GoogleNews(lang='pt')
#googlenews = GoogleNews(period='7d')
googlenews.set_lang('pt')
#googlenews.set_time_range('02/01/2019','08/28/2021')
#googlenews.set_time_range('07/01/2021','08/28/2021')
googlenews.set_time_range('08/28/2021','11/08/2021')
googlenews.set_encode('utf-8')
#googlenews.search('Lei Aldir Blanc')
#googlenews.result()
googlenews.get_news('Lei Aldir Blanc')
resultados_LAB = googlenews.result()
resultados_LAB2 =pd.DataFrame(resultados_LAB)
resultados_LAB3 = googlenews.get_links()
resultados_LAB4 =pd.DataFrame(resultados_LAB3)
googlenews.get_news('Lei Paulo Gustavo')
resultados_LPG = googlenews.result()
resultados_LPG2 =pd.DataFrame(resultados_LPG)
resultados_LPG3 = googlenews.get_links()
resultados_LPG4 =pd.DataFrame(resultados_LPG3)
DATE=strftime("%Y-%m-%d")
backupfile_LAB = "Lei_Aldir_Blanc_" + DATE + ".csv"
backupfile_LPG = "Lei_Paulo_Gustavo_" + DATE + ".csv"
backupfile_LAB4 = "Lei_Aldir_Blanc_2_" + DATE + ".csv"
backupfile_LPG4 = "Lei_Paulo_Gustavo_2_" + DATE + ".csv"
resultados_LAB2.to_csv(backupfile_LAB, encoding='utf-8', index=False)
resultados_LPG2.to_csv(backupfile_LPG, encoding='utf-8', index=False)
resultados_LAB4.to_csv(backupfile_LAB4, encoding='utf-8', index=False)
resultados_LPG4.to_csv(backupfile_LPG4, encoding='utf-8', index=False)
@DATAUNIRIO
Copy link
Author

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment