I used the following as a guide, and being brand-new to python, cannot figure how to implement it for my data set.
How to extract tables from websites in Python
My problem is I want to convert the following table into CSV format, I thought the solution above would work, but alas, no go.
import requests
import pandas as pd
url = '
html = requests.get(url).content
df_list = pd.read_html(html)
df = df_list[-1]
print(df)
df.to_csv('my data.csv')
Pavlos suggestion:
import csv, requests
from bs4 import BeautifulSoup
html = requests.get(url)
connection = html.text
soup = bs4.BeautifulSoup(connection, 'lxml')
list_header = []
for items in header:
try:
list_header.append(items.get_text())
except:
continue
HTML_data = soup.find_all("table")[0].find_all("tr")[1:]
for element in HTML_data:
sub_data = []
for sub_element in element:
try:
sub_data.append(sub_element.get_text())
except:
continue
data.append(sub_data)
dataFrame = pd.DataFrame(data = data, columns = list_header)
dataFrame.to_csv('Overflow.csv')