Created
May 10, 2024 20:26
-
-
Save michalcza/0bae34b9bd8d0d6492ed6144be57d896 to your computer and use it in GitHub Desktop.
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
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