Created
January 25, 2016 19:54
-
-
Save aVolpe/3005fe98a293a845f9a2 to your computer and use it in GitHub Desktop.
Ejemplo de scraping con python para curso de open data
This file contains 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
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