2

Este es mi código:

import urllib2
response = urllib2.urlopen('http://python.org/')
html = response.read ()
print (html) 

Este es el error que tengo:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    import urllib2
ImportError: No module named 'urllib2'

1 respuesta 1

3

En Python 3, urlopen ha sido movido. Lo que tienes que hacer ahora es:

from urllib.request import urlopen

response = urlopen('http://python.org/')

Esto está especificado en la documentación de urllib2 para Python 2:

Note: The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.