Scrapy 项目输出为元组而不是列表

Bil*_*hon 0 scrapy

无论出于何种原因,所有项目都作为元组返回。不知道我错过了什么。在所有其他蜘蛛和项目中,它只是一个列表(当我使用提取()时)。

{'acne': (None,),
'function': ([u'\u2027Preservative'],),
'function0': u'\u2027Preservative',
'irritant': (None,),
'name': (u'Potassium Sorbate',),
'safety': (u'3',),
'url': 'http://cosdna.com/eng/383bb7435.html'}
Run Code Online (Sandbox Code Playgroud)

这是我的蜘蛛代码。

def parse(self, response):
    inspect_response(response, self)
    a = response.xpath('//table//tr')

    for i in a:
        item = CosdnaExtItem()
        item['name'] = i.xpath('./td/a/text()').extract_first(),
        item['url'] = i.xpath('./td/a/@href').extract_first(),
        item['function'] = i.xpath('.//td[2]/span//text()').extract(),
        item['acne'] = i.xpath('.//td[3]/span//text()').extract_first(),
        item['irritant'] = i.xpath('.//td[4]/span//text()').extract_first(),
        item['safety'] =  i.xpath('.//td[5]/div//text()').extract_first(),

        yield item
Run Code Online (Sandbox Code Playgroud)

Mik*_*bov 5

请注意行尾的额外逗号:

item['function'] = i.xpath('.//td[2]/span//text()').extract(),
Run Code Online (Sandbox Code Playgroud)

在 Python 中

x = y,
Run Code Online (Sandbox Code Playgroud)

是相同的

x = (y,)
Run Code Online (Sandbox Code Playgroud)