Pandas – Tabelle von einer Webseite

Pandas – Tabelle von einer Webseite


Pandas can do this right out of the box, saving you from having to parse the html yourself. to_html() extracts all tables from your html and puts them in a list of dataframes. to_csv() can be used to convert each dataframe to a csv file. For the web page in your example, the relevant table is the first one, which is why I used df_list[0] in the code below.

import requests
import pandas as pd

url = ''
html = requests.get(url).content
df_list = pd.read_html(html)
df = df_list[0] # Nummer der tabelle
df.to_csv('my data.csv')

Die Kommentare sind geschloßen.