Scope writing XPath expression for unknown depth

I have a html file similar to:

<div id='author'> 
   <div>
      <div>
         ...

             <a> John Doe </a>

      

I don't know how many divs there will be under the div author. It can have different depths for different pages.

So what would be the XPath expression for this type of xml?

By the way, I've tried:

//div[@id = "author"]/*/a/text()

      

but that only seems to be for the author div's grandchildren.

+3


source to share


1 answer


Use the double slash to find an element a

anywhere in an element div

with id="author"

:



//div[@id = "author"]//a/text()

      

+4


source







All Articles