Alexander Yau Alexander Yau - 1 year ago 129
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!

Answer Source

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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download