2

I am trying to get matchID from JSON data, however, got below TypeError.Could someone please advise solution here?

URL: 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)

Error: TypeError: list indices must be integers or slices, not str

Thanks in advance.

0

1 Answer 1

1

This is because data is a list of json. So you need:

for d in data: 
    matchID = d['matchID']
    print (matchID)
Sign up to request clarification or add additional context in comments.

1 Comment

Gotcha. Thanks for answering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.