0

My json url has this:

{years=["2014","2015","2016"]}

How can I get this strings from URL with Python 3? I know this method but Python 3 has no urllib2 module.

import urllib2
import json
response = urllib2.urlopen('http://127.0.0.1/years.php')
data = json.load(response)   
print (data)

ImportError: No module named 'urllib2'

kadir_cakir
  • 1,013
  • 1
  • 16
  • 22

1 Answers1

1

Try changing the import to urllib, and use urllib.request instead. For the reason being, please refer to this SO Answer

import urllib
import json

response = urllib.request.urlopen('http://127.0.0.1/years.php')
data = json.load(response)   
print (data)
Community
  • 1
  • 1
Anzel
  • 19,825
  • 5
  • 51
  • 52