Skip to content

Instantly share code, notes, and snippets.

@michalcza
Created May 10, 2024 20:26
Show Gist options
  • Save michalcza/0bae34b9bd8d0d6492ed6144be57d896 to your computer and use it in GitHub Desktop.
Save michalcza/0bae34b9bd8d0d6492ed6144be57d896 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import csv
# Read HTML content from file
with open('table.txt', 'r', encoding='utf-8') as file:
html_content = file.read()
# Parse HTML
soup = BeautifulSoup(html_content, 'html.parser')
# Extract table data
table_data = []
for row in soup.find('table').find_all('tr'):
cols = row.find_all(['th', 'td'])
cols = [col.text.strip() for col in cols]
table_data.append(cols)
# Write to CSV file
with open('torque_settings.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(table_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment