Created
September 10, 2013 19:16
-
-
Save eliezerfot123/6514221 to your computer and use it in GitHub Desktop.
Como traer el html de una página web con python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/lib/env python | |
#Utilizamos la libreria de python urllib2 | |
import urllib2 | |
def contenidoPagina(url): | |
try: | |
traer = urllib2.urlopen(page) | |
# leemos el contenido que trae la pagina. | |
datos = traer.read() | |
#Cerramos la conexión | |
f.close() | |
return datos | |
except urllib2.HTTPError, error: | |
# Mostrar un posible de error... | |
return error.reason | |
print contenidoPagina("http://www.google.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Te recomiendo echar una mirada a
requests
, es la librería "de facto" en Python para HTTP. No me extrañaría que la incorporaran en la std library en el mediano plazo.https://pypi.python.org/pypi/requests
http://python-requests.org/