close

raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
前陣子再寫一個json crawler在測試時跑起來都滿OK的。
就把他加進去cron裏面跑,
結果他一直吐 No JSON object could be decoded。

問題
url透過 urlopen開啟再read()
好像會讓他讀不到內容。
註解掉的是舊的寫法,
可能再加入shell script後,read方面出了問題。
索性直接改成json.load(f)的方式。



def get_page(url):
#html=urllib2.urlopen(url).read()
#htmlx=simplejson.loads(html)
#htmlx=json.loads(html)
#120505 add json.load(f)
html=urllib2.urlopen(url)
htmlx=json.load(html)
return int(htmlx.get('page_all'))/10+1


Get json data via url and use in python (simplejson) - Stack Overflow
http://stackoverflow.com/questions/1640715/get-json-data-via-url-and-use-in-python-simplejson


arrow
arrow
    文章標籤
    python json
    全站熱搜
    創作者介紹
    創作者 peicheng 的頭像
    peicheng

    FLASHC

    peicheng 發表在 痞客邦 留言(0) 人氣()