[英]How to select an element that matches a part of the element's inner text using XPATH with JavaScript
[英]How to select inner text of the link using XPath?
我正在使用Scrapy
來抓取數據。
在我的瀏覽器上的JS
控制台上,我輸入$x('//div[@class="summary"]//div[contains(@class, "tags")]')
來獲得我需要的東西,但我需要過濾數據。
下圖是$x('//div[@class="summary"]//div[contains(@class, "tags")]')
命令結果。
我應該如何編寫xpath
命令來獲取綠色框中的數據? 我試過$x('//div[@class="summary"]//div[contains(@class, "tags")]//a[contains(@class, "post-tag")]')
,但這不是我想要的。
謝謝!
要在所選div
選擇<a>
元素的內部文本,您只需要將/a/text()
附加到選擇div
XPath:
//div[@class="summary"]//div[contains(@class, "tags")]/a/text()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.