Reputation: 3538
I'm fairly new to XPath and wanted to see how granular you can get when accessing various HTML components.
I'm currently using the this xpath
//*[@id=\"resultsDiv\"]/p[1]/a
to access the HTML (abbreviated) below:
<p style="margin:0;border-width:0px;"><a href="./t_Person.aspx?PersonID=140476">Bill%20Jones</a></p>
The XPath returns this: <a href="./t_Person.aspx?PersonID=140476">Bill%20Jones</a>
But what I'm trying to get is simply the PersonID = 140476.
Question: Is it possible to write an XPath that results in 140476
, or do I need to take what was returned and use a regular expression other method to access the PersonID
.
Upvotes: 1
Views: 40
Reputation: 111541
If this XPath,
//*[@id=\"resultsDiv\"]/p[1]/a
selects this a
element,
<a href="./t_Person.aspx?PersonID=140476">Bill%20Jones</a>
then this XPath,
substring-after(//*[@id='resultsDiv']/p[1]/a/@href, 'PersonID=')
will return 140476
alone, as requested.
Upvotes: 1