1

I'm trying to get the email to a friend link from this page using xpath.

http://www.guardian.co.uk/education/2009/oct/14/30000-miss-university-place

The link itself is wrapped up in tags like this

            <li><a class="rollover sendlink" href="http://www.guardian.co.uk/email/354237257"  title="Opens an email form" name="&lid={pageToolbox}{Email a friend}&lpos={pageToolbox}{2}"><img src="http://static.guim.co.uk/static/80163/common/images/icon_email-friend.gif" alt="" class="trail-icon" /><span>Send to a friend</span></a></li>

I'm using this for my query, but it's not quite right.

            $links = $xpath->query("//a/span[text()='Send to a friend']/@href");
Tom
  • 33,626
  • 31
  • 85
  • 109

4 Answers4

3

You're trying to get the href of the span there. I think you want

$links = $xpath->query("//a[span/text()='Send to a friend']/@href");
philnash
  • 70,667
  • 10
  • 60
  • 88
1

You need to use something like this (since href is an attribute of a):

$links = $xpath->query("//a[span/text()='Send to a friend']/@href");
rslite
  • 81,705
  • 4
  • 44
  • 47
1

The href is an attribute of the anchor hence you need:-

 $links = $xpath->query("//a[span[text()='Send to a friend']]/@href");
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
1

try this

 $links = $xpath->query("//a[span='Send to a friend']/@href");
Andrew Keith
  • 7,515
  • 1
  • 25
  • 41