Xpath php 获取链接 [英] Xpath php fetch links

查看:28
本文介绍了Xpath php 获取链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此示例从网站获取链接:

I'm using this example to fetch links from a website :

http://www.merchantos.com/makebeta/php/scraping-links-with-php/

$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");

for ($i = 0; $i < $hrefs->length; $i++) {
    $href = $hrefs->item($i);
    var_dump($href);
    $url = $href->getAttribute('href');
    echo "<br />Link stored: $url";
}

效果很好;获取所有链接;但我无法获得链接的实际标题";例如,如果我有:

It works well; getting all the links; but I cannot get the actual 'title' of the link; for example if i have :

<a href="www.google.com">Google</a>

我也希望能够获取Google"字词.

I want to be able to fetch 'Google' term too.

我对 xpath 有点迷茫,而且很陌生.

I'm little lost and quite new to xpath.

推荐答案

试试这个:

$link_title = $href->nodeValue;

这篇关于Xpath php 获取链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆