我正在尝试从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
提前谢谢
这是因为
data
是一个json列表。因此,您需要:相关问题 更多 >
编程相关推荐