亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類型錯誤:不能混合 str 和非 str 參數

類型錯誤:不能混合 str 和非 str 參數

MMMHUHU 2023-04-25 17:17:34
from scrapy import Spiderfrom scrapy.http import Requestclass CourseSpider(Spider):    name = 'course'    allowed_domains = ['coursera.org']    start_urls = ['https://coursera.org/about/partners']    def parse(self, response):        listings = response.xpath('//div[@class="rc-PartnerBox vertical-box"]')        for listing in listings:            title = listing.xpath('.//div[@class="partner-box-wrapper card-one-clicker flex-1"]/p').extract_first()            relative_url = listing.xpath('.//a/@href').extract_first()            absolute_url = response.urljoin(relative_url)            yield Request(response.urljoin(relative_url), callback = self.parse_listing,meta={'title':title,'absolute_url':absolute_url})    def parse_listing(self,response):        titles = response.meta.get('title')        absolute_url = response.meta.get('absolute_url')        titles_course =  response.xpath('//div[@class="name headline-1-text"]/text()').extract()        url_link = response.xpath('//div[@class="rc-Course"]/a/@href').extract()        abs_url = response.urljoin(url_link)        yield {'title':title,        'titles':title,        'absolute_url':absolute_url,        'titles_course':titles_course,        'abs_url':abs_url}但是,在通過 cmd 運行腳本時。我收到錯誤。這些錯誤表明我不能混合 str 和非 str 參數,我對如何處理這個問題感到困惑。任何幫助,將不勝感激。我嘗試添加 extract() 函數,因為它在列表容器上的一些先前的 stackoverflow 問題中被提及以消除該錯誤,但是我的 xpath 沒有獲得所需的輸出。
查看完整描述

1 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

您正在尋找.extract_first()或它的新名稱.get(),因為它.extract()會生成一個列表,不能在其中使用.urljoin



查看完整回答
反對 回復 2023-04-25
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號