Scrapy信息不是JSON可序列化的

时间:2016-12-04 05:50:12

标签: python scrapy

我正在抓取一些活动网站的信息,当我运行我的蜘蛛时,我收到了这个错误,我想知道是否有人新的如何解决它。

  File "/usr/lib/python3.4/json/encoder.py", line 173, in default raise TypeError(repr(o) + " is not JSON serializable")
  TypeError: <Selector xpath='.//a[@target="_top"]/text()' data='Artist Development Fellowship Informatio'> is not JSON serializable

我可以用以下文字抓取文字:

scrapy shell http://ofa.fas.harvard.edu/events

for event in response.xpath('.//article[@class="node node-event node-teaser article event-start clearfix"]'):
event.xpath('.//a[@target="_top"]/text()')

蜘蛛:

import scrapy


class FAS(scrapy.Spider):
    name ='fas'
    start_urls = [
        'http://ofa.fas.harvard.edu/events',
    ]

    def parse(self, response):
        for event in response.xpath('.//article[@class="node node-event node-teaser article event-start clearfix"]'):
            yield {
            'title' : event.xpath('.//a[@target="_top"]/text()'),  
             }

0 个答案:

没有答案