Skip to content

Instantly share code, notes, and snippets.

@0xbepresent
Created July 21, 2014 19:20
Show Gist options
  • Save 0xbepresent/bdc4868c681e8e2d7404 to your computer and use it in GitHub Desktop.
Save 0xbepresent/bdc4868c681e8e2d7404 to your computer and use it in GitHub Desktop.
Get a list of world's countries
# -*- 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