Dave Lowe
Dave Lowe

Reputation: 11

Parse href from <a> using XPath (@href doesn't work)

This should be simple but isn't.

I am using:

//*[@class="mainbody right"]//div[2]/div[2]/div[1]/div[1]/a

to generate a list of elements:

< a href="https://someurl1.com" class="title getFull" data-view="full"> Some plain text 1 < /a>

< a href="https://someurl2.com" class="title getFull" data-view="full"> Some plain text 2 < /a>

< a href="https://someurl3.com" class="title getFull" data-view="full"> Some plain text 3 < /a>

What I want instead is either:

href="https://someurl1.com"

href="https://someurl2.com"

href="https://someurl3.com"

or

https://someurl1.com

https://someurl2.com

https://someurl3.com

How do I get rid of the unwanted class & data-view & plain text? I have tried appending /@href and a great number of other things but to no avail.

Upvotes: 0

Views: 134

Answers (1)

Amrendra Kumar
Amrendra Kumar

Reputation: 1816

If you really want to take values from position elements then you need to change the XPath like:

//*[@class="mainbody right"]//div[2]/div[2]/div[1]/div[1]/a/@href

Upvotes: 0

Related Questions