使用PHP DOM从其他网站获取div

时间:2014-08-06 07:43:11

标签: php curl

昨天,我试图将其他网站的div带到我的网站。

我希望PHP读取给出div的信息,并比较我给出的字符串和网站给我的字符串。

这是我的代码:

//Blah, blah, blah
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML(file_get_contents('http://www.habbo.'.$hotel.'/home/'.$habbo));
$xpath = new DomXpath($dom);
$motto = $xpath->query('//*[@class="profile-motto"]')->item(0)->textContent;
echo $motto;
if($code !== $motto){
    $num_habbo = 2;
}
//Blah, blah, blah

页面示例:

  

http://www.habbo.es/home/iEnriqueSP

我想要的字符串是“Mi perfil”,在“Añadiramigo”和用户的头像之间。

当我尝试用echo $motto显示字符串时,PHP没有显示任何内容。

我不知道cURL是否需要PHP DOM,但在我的主机的PHP Info cURL中显示enable:

感谢您的关注

1 个答案:

答案 0 :(得分:0)

这样的任务有一个很好的库。

PHP Simple HTML DOM Parser

让你解析html文件并获取内部和外部文本。文档也应该非常简单。

相关问题