Skip to content

Instantly share code, notes, and snippets.

@astagi
Created March 7, 2020 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astagi/41b1b3a8efd9d2637c539110882f32c0 to your computer and use it in GitHub Desktop.
Save astagi/41b1b3a8efd9d2637c539110882f32c0 to your computer and use it in GitHub Desktop.
import requests
def get_all_planets():
page = 0
planets = []
next_url = "https://swapi.co/api/planets/"
while next_url:
resp = requests.get(next_url).json()
next_url = resp['next']
for json_planet in resp['results']:
planets.append(json_planet['name'])
yield json_planet['name']
page += 1
for planet in get_all_planets():
print (planet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment