您可以尝试:
import requests
import pandas as pd
from bs4 import BeautifulSoup
url = "https://www.quantalys.com/Fonds/Historique/19801"
api_url = "https://www.quantalys.com/Fonds/GetChartHisto_Historique?currency=EUR"
soup = BeautifulSoup(requests.get(url).content, "html.parser")
mn = soup.select_one("#date-min-produit")["value"]
mx = soup.select_one("#date-max-produit")["value"]
prod_id = soup.select_one( #produit-identifier )[ value ]
id_, type_, classe_ = prod_id.split( _ )
query = [
{
"ID": int(id_),
"Nom": soup.h1.strong.text.strip(),
"Type": int(type_),
"Color": "#0A50A1",
"FinancialItem": {
"ID_Produit": int(id_),
"cTypeFinancialItem": int(type_),
"cClasseFinancialItem": int(classe_),
"nModeCalcul": 0,
},
}
]
data = {
"ID_Produit": id_,
"jsonListeCourbes": json.dumps(query),
"sDtStart": mn,
"sDtEnd": mx,
}
data = requests.post(api_url, data=data).json()
graph = json.loads(data[ graph ])
df = pd.DataFrame(graph[ dataProvider ])
print(df.head())
打印:
x y_0
0 2004-10-27 100.00
1 2004-10-28 100.00
2 2004-10-29 100.54
3 2004-10-30 100.54
4 2004-10-31 100.54