1. 程式人生 > >scrapy AttributeError: 'str' object has no attribute 'xpath'

scrapy AttributeError: 'str' object has no attribute 'xpath'

錯誤程式碼示例:

    def parse(self, response):
        for news in response.xpath('//*[@class="Q-tpList"]/div/div/em').extract():
            title = news.xpath('a/text()').extract()[0].strip()

解決方法:

把第二行xpath的.extract()刪掉