0 Daumen
199 Aufrufe

Ich möchte ab einem bestimmten Datum Artikel aus so vielen Quellen auf der ganzen Welt importieren.

import requests
url = ('https://newsapi.org/v2/top-headlines?'
      'country=us&'
      'apiKey=de9e19b7547e44c4983ad761c104278f')
response = requests.get(url)

response_dataframe = pd.DataFrame(response.json())

articles = {article for article in response_dataframe['articles'] if article['publishedAt'] == '2019-01-04T11:30:00Z'}
print(articles)

Aber ich habe :



---------------------------------------------------------------------------
TypeError                                Traceback (most recent call last)
<ipython-input-84-0f21f2f50907> in <module>
      2 response_dataframe['articles'][1]['publishedAt']
      3
----> 4 articles = {article for article in response_dataframe['articles'] if article['publishedAt'] >= '2018-01-04T11:30:00Z'}
      5 print(articles)

<ipython-input-84-0f21f2f50907> in <setcomp>(.0)
      2 response_dataframe['articles'][1]['publishedAt']
      3
----> 4 articles = {article for article in response_dataframe['articles'] if article['publishedAt'] >= '2018-01-04T11:30:00Z'}
      5 print(articles)

TypeError: unhashable type: 'dict'

Avatar von

Ein anderes Problem?

Stell deine Frage

Willkommen bei der Stacklounge! Stell deine Frage einfach und kostenlos

x
Made by a lovely community