Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created May 14, 2021 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amankharwal/0cb5711a0f5cf142c9881a5083f6eb96 to your computer and use it in GitHub Desktop.
Save amankharwal/0cb5711a0f5cf142c9881a5083f6eb96 to your computer and use it in GitHub Desktop.
import csv
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("https://en.wikipedia.org/wiki/Comparison_of_programming_languages")
soup = BeautifulSoup(html, "html.parser")
table = soup.findAll("table", {"class":"wikitable"})[0]
rows = table.findAll("tr")
with open("language.csv", "wt+", newline="") as f:
writer = csv.writer(f)
for i in rows:
row = []
for cell in i.findAll(["td", "th"]):
row.append(cell.get_text())
writer.writerow(row)
import pandas as pd
a = pd.read_csv("language.csv")
a.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment