我正在嘗試將所有內(nèi)容都放入 p 標(biāo)簽中,包括嵌套的 b 標(biāo)簽,但是除了 b 之外,我還得到了其他所有內(nèi)容。有人可以幫我弄這個(gè)嗎?這是我的代碼:def parse(self, response): images = response.css("#mw-content-text > div > table > tbody > tr > td > a > img::attr(src)").extract_first() text1 = response.css("#mw-content-text > div > p::text").extract() text2 = ''.join(text1) yield {'text2': text2, 'image_urls':[PROTOCOL+ images]} for next_page in response.css('#mw-content-text > div > ul > li > b > a::attr(href)').extract(): yield Request(BASE_URL + next_page, callback=self.parse)
1 回答

料青山看我應(yīng)如是
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
您必須在::text
讓選擇器檢索最后一個(gè)標(biāo)簽下方的所有文本之前使用空格:
text1 = response.css("#mw-content-text > div > p ::text").extract()
添加回答
舉報(bào)
0/150
提交
取消