Last active
March 21, 2020 07:43
-
-
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/
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
# !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