Forum >> Principianti >> Come chiamare un url e aggregare i risultati in modo ricorsivo?

Pagina: 1

Buongiorno,



Voglio recuperare in un dataframe il massimo di articoli da una certa data.

Per il momento posso solo disegnare 20 titoli del giorno. Penso che sia il limite. Ho messo in colonna la fonte e il titolo e ho indicizzato la data.

import requests





url = ('https://newsapi.org/v2/everything?'

       'language=en&'

       'from=2018-12-07&'

       'to=2018-12-07&'

       'sources=financial-times,australian-financial-review,reuters,the-times-of-india&'

       'apiKey=de9e19b7547e44c4983ad761c104278f')




response = requests.get(url)






import pandas as pd

from pandas.io.json import json_normalize




# using the pandas.io.json.json_normalize() function; 

# it can produce a dataframe for you from list-and-dictionaries structure typically loaded from a JSON source.

df = json_normalize(response.json(), 'articles')




# make the datetime column a native type, and add a date-only column

df['publishedAt'] = pd.to_datetime(df['publishedAt'])

df['date'] = df['publishedAt'].dt.date




# move source dictionary into separate columns rather than dictionaries

source_columns = df['source'].apply(pd.Series).add_prefix('source_')

df = pd.concat([df.drop(['source'], axis=1), source_columns], axis=1)





df[['date', 'source_name', 'title']].set_index('date').sort_values(['date', 'source_name'])

Cosa mi dà





2018-12-07Financial TimesPound exodus: Brexit drives away US and Asia i...2018-12-07Financial TimesTillerson says Trump paid little heed to the law2018-12-07Financial TimesAirbnb rentals in London block sparks call for...2018-12-07ReutersU.S. accuses Huawei CFO of Iran sanctions cove...2018-12-07ReutersNFL notebook: Flacco questionable, could be ba...2018-12-07ReutersNFL notebook: Flacco questionable, could be ba...2018-12-07ReutersBrazil's Temer announces 'intervention' in sta...2018-12-07ReutersBoxing: WBC sanctions direct rematch between W...2018-12-07ReutersBoxing: WBC sanctions direct rematch between W...2018-12-07ReutersBrazil's Temer announces 'intervention' in sta...2018-12-07ReutersEx-Trump campaign chair lied to investigators ...2018-12-07ReutersMueller: ex-Trump campaign chair lied to inves...2018-12-07ReutersGerman finmin looking at Deutsche, Commerzbank...2018-12-07ReutersMany U.S.-bound caravan migrants disperse as a...2018-12-07The Times of IndiaLive 1st Test India vs Australia: Rain delays ...2018-12-07The Times of IndiaPlan to prosecute Asthana legally vetted: Verm...2018-12-07The Times of IndiaLS members’ MPLADS funds for 2018-19 not yet a...2018-12-07The Times of IndiaUS: Trump lawyer met Russian offering 'politic...2018-12-07The Times of IndiaThe Latest: Manafort testified before grand ju...2018-12-07The Times of IndiaThe Latest: Prosecutors say Manafort lied abou...



Come ottenere 20 risultati da queste fonti indicizzati ogni giorno?

Cioè, nella seguente forma:





pricesarticles2007-01-0112469What Sticks from '06. Somalia Orders Islamist...2007-01-0212472Heart Health: Vitamin Does Not Prevent Death ...2007-01-0312474Google Answer to Filling Jobs Is an Algorithm...2007-01-0412480Helping Make the Shift From Combat to Commerc...2007-01-0512398Rise in Ethanol Raises Concerns About Corn as...






Pagina: 1



Esegui il login per scrivere una risposta.