Abhi
Abhi

Reputation: 105

extracting an element using Xpath

    <a id="yui_3_4_1_1_1329966665861_8510" class="buy-as-gift-link" 
            data-bntrack="buyasgift" href="#purchase=9780345527721"></a>

need to extract "#purchase=9780345527721" from this element using Xpath

Upvotes: 1

Views: 92

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

Use:

//a[@id='yui_3_4_1_1_1329966665861_8510']/@href

This XPath expression selects all href attributes of all a elements that have an id attribute with string value "yui_3_4_1_1_1329966665861_8510".

In case you want to get not the attribute node (we hope that no two elements exist with the same value for id) but just its string value, this can be obtained as result of evaluating the following XPath expression:

string(//a[@id='yui_3_4_1_1_1329966665861_8510']/@href)

Upvotes: 3

Related Questions