使用json和scrapy抓取页面时出错

时间:2016-08-15 23:09:56

标签: windows python-3.x scrapy

我在Win10上使用Scrapy和Python3来搜索producthunt.com。我对我的代码行为感到困惑,这会复制输出数据中的某些字段。 任何人都可以指出原因并提出解决方案吗?

代码: http://pastebin.com/VvFGCmDJ

输出样本: http://pastebin.com/ffx0HN54

1 个答案:

答案 0 :(得分:1)

我无法运行您的代码,但创建Item实例肯定需要在for循环中:

    ...

    def parse(self, response):
        jsonresponse = json.loads(response.body_as_unicode())
        topic = jsonresponse['posts']
        for post in topic:

            service = ProducthuntItem()

            service['name'] = post['name'].replace(";", " ")
            ...