0

I use this xPath

$url = extractNodeValue('//*[@id="coremain"]/div[1]/div[1]/div/div[2]/a', $xPath);

to get the link from this HTML

<a href="http://www.domain.com" class="summary url" style="color: rgb(198, 35, 35);">Name of the link</a>

However instead of getting the link, I get the appearead name for the link. How can I fix this?

EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

2 Answers2

0

You want to get the attribute of href attribute not the nodevalue:

'//*[@id="coremain"]/div[1]/div[1]/div/div[2]/a/@href'
immulatin
  • 2,118
  • 1
  • 12
  • 13
  • Well the attribute has a nodevalue, too. Se he want's to get the nodevalue, just from a different node. And better than giving back just the codez is providing reference IMHO. – hakre Jun 25 '13 at 00:23
0

That depends on what extractNodeValue() actually does (and you have not shared the code), however by its name it extracts the node-value. And the node value of the <a> element is

"Name of the link"

So you should specify the node instead of which you want to retrieve the value of. The <a> element is normally known as link, so no clue what you mean. Probably the href attribute?

See as well:

Edit: I see now the changed title, you are indeed interested in the href attribute. It works as outlined in the link above, just prefix the attribute name with the @-symbol to make clear you are looking for an attribute:

.../a/@href

This is looking for the href attribute of the <a> element. Elements in Xpath are parent of the attributes they have. But the attributes are no children. ?! This is different to the DOM, see as well:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836