Skip to content

Instantly share code, notes, and snippets.

@sakethramanujam
Last active March 21, 2020 07:43
Show Gist options
  • Save sakethramanujam/b156c13e34e513c65db542fc5f8f0221 to your computer and use it in GitHub Desktop.
Save sakethramanujam/b156c13e34e513c65db542fc5f8f0221 to your computer and use it in GitHub Desktop.
Scraping WHO list of countries using BeautifulSoup url : https://www.who.int/countries/en/
# !usr/bin/env python3
import requests
from bs4 import BeautifulSoup
if __name__ == '__main__':
url = 'https://www.who.int/countries/en/'
content = requests.get(url).content
soup = BeautifulSoup(content,'html5lib')
divs = soup.findAll('div', attrs={'class':'largebox'})
countries = []
for div in divs:
key = div.h3.text
li = div.findAll('li')
values = []
for l in li:
values.append(l.a.text)
countries.append({key:values})
print(countries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment