BaşlayınÜcretsiz Başlayın

Fetch from an API

In the last video, you've seen that you can extract data from an API by sending a request to the API and parsing the response which was in JSON format. In this exercise, you'll be doing the same by using the requests library to send a request to the Hacker News API.

Hacker News is a social news aggregation website, specifically for articles related to computer science or the tech world in general. Each post on the website has a JSON representation, which you'll see in the response of the request in the exercise.

Bu egzersiz

Introduction to Data Engineering

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Use the requests module to get the Hacker News post's JSON object.
  • Print out the response, parsed as a JSON.
  • Parsing as JSON again, assign the "score" key of the post to post_score.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

import requests

# Fetch the Hackernews post
resp = requests.____("https://hacker-news.firebaseio.com/v0/item/16222426.json")

# Print the response parsed as JSON
print(resp.____())

# Assign the score of the test to post_score
post_score = resp.___()["____"]
print(post_score)
Kodu Düzenle ve Çalıştır