exceptions.KeyError: 'TrainingItem does not support field: start'

387 views
Skip to first unread message

zqp821...@gmail.com

unread,
Jan 23, 2015, 6:49:04 AM1/23/15
to scrapy...@googlegroups.com

class TrainingItem(Item):

    course = Field()
    desc = Field()
    start = Field
    end = Field()
    school = Field
    trainId = Field()
    id = Field()

course = hxs.xpath(u'//h3[text()="XXXX"]/../h2[%s]/text()'%x).re(r'\S+')

                if course:
                    
                    train_item["start"] = course[0]
                    
                    train_item["end"] = course[2]
                    
                    train_item["course"] = course[3]




2015-01-23 19:32:14+0800 [zlzp] ERROR: Spider error processing <GET 
        Traceback (most recent call last):
          File "C:\python27\lib\site-packages\twisted\internet\base.py", line 82
4, in runUntilCurrent
            call.func(*call.args, **call.kw)
          File "C:\python27\lib\site-packages\twisted\internet\task.py", line 63
8, in _tick
            taskObj._oneWorkUnit()
          File "C:\python27\lib\site-packages\twisted\internet\task.py", line 48
4, in _oneWorkUnit
            result = next(self._iterator)
          File "C:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg\scrapy\uti
ls\defer.py", line 57, in <genexpr>
            work = (callable(elem, *args, **named) for elem in iterable)
        --- <exception caught here> ---
          File "C:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg\scrapy\uti
ls\defer.py", line 96, in iter_errback
            yield next(it)
          File "C:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg\scrapy\con
trib\spidermiddleware\offsite.py", line 26, in process_spider_output
            for x in result:
          File "C:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg\scrapy\con
trib\spidermiddleware\referer.py", line 22, in <genexpr>
            return (_set_referer(r) for r in result or ())
          File "C:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg\scrapy\con
trib\spidermiddleware\urllength.py", line 33, in <genexpr>
            return (r for r in result or () if _filter(r))
          File "C:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg\scrapy\con
trib\spidermiddleware\depth.py", line 50, in <genexpr>
            return (r for r in result or () if _filter(r))
          File "C:\Users\Administrator\Desktop\ZLZP\ZLZP\zlzp_spiders\spiders_co
okie.py", line 392, in parse_item
            train_item["start"] = course[0]
          File "C:\python27\lib\site-packages\scrapy-0.24.4-py2.7.egg\scrapy\ite
m.py", line 57, in __setitem__
            (self.__class__.__name__, key))
        exceptions.KeyError: 'TrainingItem does not support field: start'

Paul Tremberth

unread,
Jan 23, 2015, 6:56:29 AM1/23/15
to scrapy...@googlegroups.com
You're missign parentheses for the "start" field:

class TrainingItem(Item):

    course = Field()
    desc = Field()
    start = Field()   # <--- here

zqp821...@gmail.com

unread,
Jan 25, 2015, 3:16:37 AM1/25/15
to scrapy...@googlegroups.com
thanks

在 2015年1月23日星期五 UTC+8下午7:56:29,Paul Tremberth写道:

赵赵启朋

unread,
May 18, 2015, 7:05:54 AM5/18/15
to scrapy...@googlegroups.com

Thank you Paul.

--
You received this message because you are subscribed to a topic in the Google Groups "scrapy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scrapy-users/USYu0yrHVvw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scrapy-users...@googlegroups.com.
To post to this group, send email to scrapy...@googlegroups.com.
Visit this group at http://groups.google.com/group/scrapy-users.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages