【发布时间】:2014-05-15 07:39:51
【问题描述】:
我一直在尝试使用简单的 html dom 和 XPath 抓取网站页面并搜索特定文本。我已经从网站上获取了所有链接,并尝试在所有页面上抓取这些链接和搜索文本。我要搜索的文本在 html span 标签内。
但是没有显示输出。
怎么了?
这是我的代码
<?php
include_once("simple_html_dom.php");
set_time_limit(0);
$path='http://www.barringtonsports.com';
$html = file_get_contents($path);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for($i = 0; $i < $hrefs->length; $i++ ){
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
$nurl = $path.$url;
$html1 = file_get_contents($nurl);
$dom1 = new DOMDocument();
@$dom1->loadHTML($html1);
$xpath1 = new DOMXPath($dom1);
$name = $xpath1->evaluate("//span[contains(.,'Asics Gel Netburner 15 Netball Shoes')]");
if($name)
echo"text found";
}
?>
我只想检查网站 www.barringtonsports.com 的任何页面中是否存在“Asics Gel Netburner 15 Netball Shoes”文字。
【问题讨论】:
标签: xpath simple-html-dom web-crawler