[英]Python no json object could be decoded
我正在嘗試創建一個簡單的“ Kahoot!”登錄名。 測驗。 我想做的第一件事是從“ https://kahoot.it/#/ ” JSON對象加載,以便我可以在其中填寫表格(我嘗試使用“ mechenize”填寫表格,但它似乎僅支持html表單)。 當我運行下一個腳本時,我得到了無法解碼json的異常:
import urllib, json
url = "https://kahoot.it/#/"
response = urllib.urlopen(url)
data = json.loads(response.read())
print data
輸出:
ValueError: No JSON object could be decoded
有任何想法嗎? , 謝謝。
type(response.read())
是str
,表示頁面的HTML
。 顯然,這不是有效的JSON
因此您會收到該錯誤。
編輯如果您嘗試登錄到該頁面,則可以使用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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.