通过下面的代码,我只得到空白页的名称或昵称没有得到回显。我越过检查路径其正确仍然没有任何回应Xpath返回空白页不回显值
<?php
$url="http://www.mans-best-friend.org.uk/dog-breeds-alphabetical-list.htm";
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1');
$html = curl_exec($curl_handle);
curl_close($curl_handle);
$mydoc = new DOMDocument();
libxml_use_internal_errors(TRUE); //disable libxml errors
if(empty($html)) die("EMPTY HTML");
$mydoc->loadHTML($html);
libxml_clear_errors(); //remove errors for yucky html
$my_xpath = new DOMXPath($mydoc);
//////////////////////////////////////////////////////
$nodes = $my_xpath->query('//*[@id="table94"]/tbody/tr/td');
foreach($nodes as $node)
{
$title=$my_xpath->query('p[@data-iceapc="1"]/span/a/font', $node);
$nickname=$my_xpath->query('p[@data-iceapc="2"]/span/a/font', $node);
echo $title." ".$nickname."<br>";
}
?>
如果你找不到p元素。滚动到狗名称的部分。对于例如Affenpinscher右键点击它并选择检查 - 它显示p元素。
如果我看看你的引用链接的源代码,不存在'与'数据iceapc p'元'属性。因此你的xpath不能匹配。 –
它在那里...滚动到狗名称的部分.g Affenpinscher右键单击它并选择检查...它显示p元素 –
此属性来自此页面上的许多跟踪器之一。尝试启用某个adblock,或只是观看curl获得的html代码,您将看到该属性不是原始源代码的一部分。 –