美文网首页
使用scrapy爬取时遇到错误TypeError: 'b

使用scrapy爬取时遇到错误TypeError: 'b

作者: 悟饭哪 | 来源:发表于2017-12-13 02:52 被阅读102次

我的代码是这样写的

def parse(self, response):
        sel = scrapy.selector.Selector(response)
        sites = sel.xpath('//div[@class="title-and-desc"]')
        items = []
        for site in sites:
            item = DmozItem()
            item['title'] = site.xpath('a/div/text()').extract()
            item['link'] = site.xpath('a/@href').extract()
            item['desc'] = site.xpath('div/text()').extract()
            items.append[item]

        return items

就错在这名items.append[item],这里的“[]”应该写成“()”,改成items.append(item)就可以了。
应该是python版本更新后语法有变化了吧。

相关文章

网友评论

      本文标题:使用scrapy爬取时遇到错误TypeError: 'b

      本文链接:https://www.haomeiwen.com/subject/hmwoixtx.html