1. ホーム
  2. パイソン

scrapy AttributeError: 'str' オブジェクトには 'xpath' という属性がありません。

2022-02-24 07:20:29

エラーコードの例です。

    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 の 2 行目から .extract() を削除します。