Created
July 21, 2014 19:20
-
-
Save 0xbepresent/bdc4868c681e8e2d7404 to your computer and use it in GitHub Desktop.
Get a list of world's countries
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
# -*- coding: utf-8 -*- | |
""" | |
Get a list of world's countries | |
@author: misalabs | |
""" | |
import requests | |
from bs4 import BeautifulSoup | |
# Get countries | |
countries_html = requests.get('http://es.wikipedia.org/wiki/Anexo:Pa%C3%ADses_del_mundo') | |
# Construct Soup | |
page_countries = BeautifulSoup(countries_html.text) | |
table_countries = page_countries.findAll('table')[0] | |
countries_all = [] | |
for idx, row in enumerate(table_countries.findAll('tr')): | |
cells_country = row.findAll('td')[1:2] | |
for country in cells_country: | |
countries_all.append(country.getText()) | |
print countries_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment