通過beautifulsoup,我可以訪問此網頁的內容:
例如,如果我使用 Firefox 檢查此影像,我會在控制臺中得到以下代碼:

如您所見,我們已經獲得了顯示在模態視窗中的資訊。
因此,我想知道如何獲取出現在模態視窗中的此內容的 URL 或如何使用 BeautifulSoup 網路抓取此內容?
uj5u.com熱心網友回復:
您在頁面上看到的資料是從外部 URL 加載的。您可以使用此示例加載資料并創建帶有評分統計資料的資料框:
import re
import json
import requests
import pandas as pd
url = "https://www.fiba.basketball/euroleaguewomen/21-22/game/1310/MBA-Moscow-ZVVZ-USK-Praha#tab=shot_chart"
api_url = "https://livecache.sportresult.com/node/db/FIBASTATS_PROD/{event_id}_GAME_{rsc}_JSON.json?s=unknown&t=0"
html_doc = requests.get(url).text
event_id = re.search(r"setEventId\('(.*?)'\)", html_doc).group(1)
rsc = re.search(r"rsc: '(.*?)'", html_doc).group(1)
data = requests.get(api_url.format(event_id=event_id, rsc=rsc)).json()
# print full data:
# print(json.dumps(data, indent=4))
# print basic table:
df = pd.json_normalize(data["content"]["full"]["ScoreList"]).explode("Items")
df = pd.concat([df, df.pop("Items").apply(pd.Series)], axis=1)
print(df)
印刷:
Period AC C1 Code SA SB Score Team Time
0 Q1 P2 P_204187 2 0 2 0-2 T_65512 09:00
0 Q1 P3 P_151112 5 0 5 0-5 T_65512 07:48
0 Q1 P2 P_174621 7 0 7 0-7 T_65512 06:40
0 Q1 P3 P_204187 10 0 10 0-10 T_65512 06:15
0 Q1 P2 P_174621 12 0 12 0-12 T_65512 05:41
0 Q1 P2 P_160522 10 2 12 2-12 T_9998 03:57
0 Q1 P2 P_195803 8 4 12 4-12 T_9998 03:29
0 Q1 P2 P_204187 10 4 14 4-14 T_65512 02:55
0 Q1 P2 P_174621 12 4 16 4-16 T_65512 01:24
0 Q1 P3 P_137210 9 7 16 7-16 T_9998 00:57
0 Q1 P2 P_160420 11 7 18 7-18 T_65512 00:33
0 Q1 FT P_174621 12 7 19 7-19 T_65512 00:11
1 Q2 P2 P_219548 14 7 21 7-21 T_65512 09:26
1 Q2 P3 P_204187 17 7 24 7-24 T_65512 08:30
1 Q2 P2 P_219548 19 7 26 7-26 T_65512 08:05
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/317033.html
上一篇:分別從每列中選擇值
