【发布时间】:2017-07-25 10:45:59
【问题描述】:
我如何告诉 Scrapy 将所有产生的项目分成两个列表?例如,假设我有两种主要类型的项目 - article 和 author。我想将它们放在两个单独的列表中。现在我得到输出 JSON:
[
{
"article_title":"foo",
"article_published":"1.1.1972",
"author": "John Doe"
},
{
"name": "John Doe",
"age": 42,
"email": "foo@example.com"
}
]
如何将它转换成这样的东西?
{
"articles": [
{
"article_title": "foo",
"article_published": "1.1.1972",
"author": "John Doe"
}
],
"authors": [
{
"name": "John Doe",
"age": 42,
"email": "foo@example.com"
}
]
}
我输出这些的函数很简单,类似于:
def parse_author(self, response):
name = response.css('div.author-info a::text').extract_first()
print("Parsing author: {}".format(name))
yield {
'author_name': name
}
【问题讨论】: