Python 3 Get HTTP page

Viewed 56505

How can I get python to get the contents of an HTTP page? So far all I have is the request and I have imported http.client.

6 Answers

Using urllib.request is probably the easiest way to do this:

import urllib.request
f = urllib.request.urlopen("http://stackoverflow.com")
print(f.read())

pip install requests

import requests

r = requests.get('https://api.spotify.com/v1/search?type=artist&q=beyonce')
r.json()

https://stackoverflow.com/a/41862742/8501970 Check this out instead. Its about the same issue you have and this one is very simple and very few lines of codes. This sure helped me when i realized python3 cannot use simply get_page.

This is a fine alternative. (hope this helps, cheers!)

Related