Alexander Yau Alexander Yau - 8 months ago 40
Javascript Question

xpath, how to filter href content

I am using

to crawl data.

console on my browser, I type
$x('//div[@class="summary"]//div[contains(@class, "tags")]')
to get what I need, but I need to filter the data.

The following picture is the
$x('//div[@class="summary"]//div[contains(@class, "tags")]')
command result.

JS console result

How should I write
command to get the data in the green box? I tried
$x('//div[@class="summary"]//div[contains(@class, "tags")]//a[contains(@class, "post-tag")]')
, but that is not what I want。

Thank you!


To select inner text of <a> element within the selected div, you only need to append /a/text() to your XPath which selects the div :

//div[@class="summary"]//div[contains(@class, "tags")]/a/text()