import requests from bs4 import BeautifulSoup import csv
f = csv.writer(open(‘world-presidents.csv’, ‘w’)) f.writerow([‘S.No’, ‘Country’,‘President’,‘Prime-Minister’])
page = requests.get(‘http://bankersdaily.in/list-of-current-prime-ministers-president-in-world-updated-till-may-2018-static-gk’) soup = BeautifulSoup(page.text, ‘html.parser’)
president_name_list = soup.find(class_=‘content’)
president_name_list_items = president_name_list.find_all(‘td’) president_name_list = soup.find(class_=‘content’) president_name_list_items = president_name_list.find_all(‘td’)
for president_name in president_name_list_items: names = president_name.contents[0]
f.writerow([names])
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!