[英]How do I get with a xpath method a number instead of text in the Scrapy output file?
[英]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.