简体   繁体   中英

Python no json object could be decoded

I'm trying to create a simple login into a "Kahoot!" quiz . First thing i'm trying to do is load from " https://kahoot.it/#/ " JSON objects so i could fill the form in it (i tried to fill the form using 'mechenize' but its seems to support only html forms). when im running the next script im getting exception that json could not be decoded:

import urllib, json
url = "https://kahoot.it/#/"
response = urllib.urlopen(url)
data = json.loads(response.read())
print data

output:

ValueError: No JSON object could be decoded

Any ideas? , Thanks.

type(response.read()) is str , representing the HTML of the page. Obviously it's not a valid JSON therefore you are getting that error.

EDIT If you are trying to login to that page, it is possible with selenium :

from selenium import webdriver

url = "https://kahoot.it/#/"
driver = webdriver.Chrome() # or webdriver.Firefox()
driver.get(url)

# finding the text field and 'typing' the game pin
driver.find_element_by_xpath('//*[@id="inputSession"]').send_keys('your_game_pin')
# finding and clicking the sumbit button
driver.find_element_by_xpath('/html/body/div[3]/div/div/div/form/button').click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM