1

我制作了一个管道将scrapy数据放入我的 Parse Backend

解析 = 'api.parse.com' 端口 = 443

但是,我找不到在 Parse 中发布数据的正确方法。因为每次它在我的 Parse DB 中创建未定义的对象。

 class Newscrawlbotv01Pipeline(object):
    def process_item(self, item, spider):
        for data in item:
            if not data:
                raise DropItem("Missing data!")
        connection = httplib.HTTPSConnection(
            settings['PARSE'],
            settings['PORT']
        )
        connection.connect()
        connection.request('POST', '/1/classes/articlulos', json.dumps({item}), {
       "X-Parse-Application-Id": "XXXXXXXXXXXXXXXX",
       "X-Parse-REST-API-Key": "XXXXXXXXXXXXXXXXXXX",
       "Content-Type": "application/json"
     })
        log.msg("Question added to PARSE !", level=log.DEBUG, spider=spider)
        return item

错误示例:

TypeError: set([{'image': 'http://apps.site.lefigaro.fr/sites/apps/files/styles/large/public/thumbnails/image/sport24.png?itok=caKsKUzV',
 'language': 'FR',
 'publishedDate': datetime.datetime(2016, 3, 16, 21, 53, 10, 289000),
 'publisher': 'Le Figaro Sport',
 'theme': 'Sport',
 'title': u'Pogba aurait rencontr\xe9 les dirigeants du PSG',
 'url': u'sport24.lefigaro.fr/football/ligue-des-champions/fil-info/prolongation-entre-le-bayern-et-la-juve-796778'}]) is not JSON serializable
4

2 回答 2

0

我找到了解决方案

class Newscrawlbotv01Pipeline(object):
def process_item(self, item, spider):
    for data in item:
        if not data:
            raise DropItem("Missing data!")
    connection = httplib.HTTPSConnection(
        settings['PARSE'],
        settings['PORT']
    )

    connection.connect()
    connection.request('POST', '/1/classes/Articles', json.dumps(dict(item)), {
   "X-Parse-Application-Id": "WW",
   "X-Parse-REST-API-Key": "WW",
   "Content-Type": "application/json"
 })
    log.msg("Question added to PARSE !", level=log.DEBUG, spider=spider)
    return item
    #self.collection.update({'url': item['url']}, dict(item), upsert=True)
于 2016-03-20T14:28:34.920 回答
0

看起来你有一个setinside item['data'],它不被 JSON 接受。

在尝试使其 JSON 可接受之前,您需要将该字段更改回列表。

于 2016-03-16T21:38:32.700 回答