Python/JSON TypeError:列表索引必须是整数或片,而不是str

2024-10-17 08:35:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从JSON数据中获取matchID,但是,得到了下面的TypeError。有人可以在这里建议解决方案吗

网址:https://bet.hkjc.com/football/getJSON.aspx?jsontype=schedule.aspx

from selenium import webdriver
import requests
import json

match_day_url = 'https://bet.hkjc.com/football/getJSON.aspx?jsontype=schedule.aspx'
driver = webdriver.Chrome(options=options,executable_path=r"XXXXXX")
driver.get(match_day_url)
time.sleep(3)
#print(driver.page_source,'lxml')


pre = driver.find_element_by_tag_name("pre").text
data = json.loads(pre)
matchID = data['matchID']
print (matchID)

错误: TypeError:列表索引必须是整数或片,而不是str

提前谢谢


Tags: httpsimportcomdriverpreschedulewebdriverfootball