我正在使用 Scrapy,我正在嘗試抓取這樣的內容:<html> <div class='hello'> some elements . . . </div> <div class='hi there'> <div> <h3> title </h3> <h4> another title </h4> <p> some text ..... </p> "some text without any tag" <div class='article'> some elements . . </div> <div class='article'> some elements . . </div> <div class='article'> some elements . . </div> </div> </div></html>如果我想從類名“hi There”的 div 下以及類名“article”的 div 之前的所有元素中提取文本,是否有任何可能的方法使用 XPath 或 CSS 選擇器進行枯萎?
1 回答

倚天杖
TA貢獻1828條經驗 獲得超3個贊
沒用過Scrapy。
不知道它有什么功能,但是
//div[@class='hi there']/div/(div[@class='article'])[1]/preceding-sibling::*
挑選出 div 之前具有“article”類的元素,并且,
//div[@class='hi there']/div/(div[@class='article'])[1]/preceding-sibling::text()
在文章 div 之前為您提供內部文本。
添加回答
舉報
0/150
提交
取消