xpath在页面中查找特定链接 [英] xpath find specific link in page
本文介绍了xpath在页面中查找特定链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用xpath从此页面将电子邮件发送给朋友链接.
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");
推荐答案
您正在尝试获取该范围的href.我想你想要
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");
这篇关于xpath在页面中查找特定链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文