Home > Software design >  Getting text within <a > tag inside <p> tag
Getting text within <a > tag inside <p> tag

Time:10-22

Hi i have been trying to get all the text part within the div - p tags up to the hr tag so somebody gave this xpath

//div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]/text()

which works fine but this ignores the text part within the <.a> tag in the p tag any ideas to grab that text as well?

<div class="entry">
   <p> some text</p>
   <p> some text2</p>
   <p> some text3</p>
   <p> some text4
       <a href='somelink'> this text here i want to get through xpath</a>
       some text5
   </p>
   <hr>(up to this hr tag)
   <p> some text5</p>
   <hr>
   <p> some text6</p>
</div>

CodePudding user response:

One way might be //div[@]/*[not(preceding-sibling::hr | self::hr)]//text() though I might prefer to simply select the elements //div[@]/*[not(preceding-sibling::hr | self::hr)] and use the string value.

  • Related