Skip to content

Instantly share code, notes, and snippets.

@eliezerfot123
Created September 10, 2013 19:16
Show Gist options
  • Save eliezerfot123/6514221 to your computer and use it in GitHub Desktop.
Save eliezerfot123/6514221 to your computer and use it in GitHub Desktop.
Como traer el html de una página web con python
#!/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")
@glarrain
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment