Skip to content

Instantly share code, notes, and snippets.

@aVolpe
Created January 25, 2016 19:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aVolpe/3005fe98a293a845f9a2 to your computer and use it in GitHub Desktop.
Save aVolpe/3005fe98a293a845f9a2 to your computer and use it in GitHub Desktop.
Ejemplo de scraping con python para curso de open data
import urllib2
from bs4 import BeautifulSoup
e = urllib2.urlopen("http://es.wikipedia.org/wiki/Paraguay").read()
soup = BeautifulSoup(e, 'html.parser')
# Ejemplo de como imprimir todo
# print soup.prettify()
# Obtenemos la tabla
tabla_paraguay = soup.find_all('table', 'wikitable')[1]
# Obtenemos todas las filas
rows = tabla_paraguay.find_all("tr")
for row in rows:
# obtenemos todas las columns
cells = row.find_all("td")
linea = ""
for cell in cells:
linea += cell.get_text() + '\t'
#imprimos la fila
print linea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment