I am fairly new to Python and Scrapy but have been able to some basic web scraping. However, I am having issues import JSON data. I have posted the traceback after the code.
Here is the code that I am using.
from scrapy.spider import Spider
import json
class myspider(Spider):
name = "jsontest"
allowed_domains = ["data.sportsillustrated.cnn.com"]
start_urls = ['http://data.sportsillustrated.cnn.com/jsonp/basketball/nba/gameflash/2012/11/20/32128_playbyplay.json']
def parse(self, response):
jsonresponse = json.loads(response.body_as_unicode())
print jsonresponse
Traceback (most recent call last): File "C:\Python27\lib\site-packages\twisted\internet\base.py", line 1201, in mainLoop self.runUntilCurrent() File "C:\Python27\lib\site-packages\twisted\internet\base.py", line 824, in runUntilCurrent call.func(*call.args, **call.kw) File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 382, in callback self._startRunCallbacks(result) File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 490, in _startRunCallbacks self._runCallbacks() --- --- File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 577, in _runCallbacks current.result = callback(current.result, *args, **kw) File "jsontest\spiders\jsontest.py", line 10, in parse jsonresponse = json.loads(response.body_as_unicode()) File "C:\Python27\lib\json__init__.py", line 338, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\json\decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") exceptions.ValueError: No JSON object could be decoded