Scraping Data Tabel HTML Wikipedia (with Python) - hkaLabs
Wed Jul 06 2022 16:03:08 GMT+0000 (Coordinated Universal Time)
Saved by
@FajarHarris
import csv
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen('https://en.wikipedia.org/wiki/Comparison_of_text_editors')
bsObj = BeautifulSoup(html, 'html.parser')
#The main comparison table is currently the first table on the page (index [0])
table = bsObj.findAll("table", {"class":"wikitable"})[0]
rows = table.findAll("tr")
csvFile = open("../wswp/files/editors.csv", 'w+')
writer = csv.writer(csvFile)
try:
for row in rows:
csvRow = []
for cell in row.findAll(['td', 'th']):
csvRow.append(cell.get_text())
writer.writerow(csvRow)
finally:
csvFile.close()
content_copyCOPY
https://hkalabs.com/scraping-data-tabel-html-wikipedia-with-python/
Comments