Scrapy:Spider错误处理,即使与教程相同

时间:2019-04-17 12:36:16

标签: python-3.x scrapy

我有一个非常基本的蜘蛛,应该抓取这个网址: 'https://search.siemens.com/en/?q=iot/'

但是我得到的错误并不多。我检查了淹没情况,没事。


import scrapy
import json
from pprint import pprint
class SiemensSpiderSpider(scrapy.Spider):
    name = 'siemens-spider'
    start_urls = ['https://search.siemens.com/en/?q=iot/']
    def parse(self, response):
        results = json.loads(response.body)
        pprint(results)

我的完整日志:

(base) tobi@derGeraet:~/Dokumente/Dokumente/Python Scripts/Webscraping/siemens/siemens/spiders$ scrapy crawl siemens-spider -L WARN
2019-04-17 14:21:56 [scrapy.core.scraper] ERROR: Spider error processing <GET https://search.siemens.com/en/?q=iot/> (referer: None)
Traceback (most recent call last):
  File "/home/tobi/anaconda3/lib/python3.7/site-packages/twisted/internet/defer.py", line 654, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "/home/tobi/Dokumente/Dokumente/Python Scripts/Webscraping/siemens/siemens/spiders/siemens_spider.py", line 9, in parse
    results = json.loads(response.body)
  File "/home/tobi/anaconda3/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/home/tobi/anaconda3/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/tobi/anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

0 个答案:

没有答案