簡體   English   中英

我一直在 XPath 輸出中獲取 HTML! 我如何只獲取文本?

[英]I keep getting HTML in the XPath output! How do i just get text?

我一直在獲取 HTML 以及我正在運行的 Xpath 中想要的文本,但我不知道如何停止它,因為我只想要文本。

Xpath

hxs.xpath('//h1[@class="body2"]').extract()

HTML

<div class="product-title cf">


            <h1 itemprop="name" class="body2">
                Cornish Ale Dozen - Case of 12
            </h1>


</div>

任何建議將不勝感激謝謝

獲取文本節點而不是父元素的純 XPath 指令如下:

//h1[@class="body2"]/text()

特別是,假設用於執行 XPath 的庫是 Scrapy,使用上述 XPath 應該可以按預期工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM