我有以下这样的天气site
我需要使用Xpath但是返回查询!
我正在使用此xPath并且必须返回2行
$xpath->query('/html/body/table[3]/tbody/tr/td/table/tbody/tr/td[2]/p/table/tbody/tr/td/font/div/center/table/tbody/tr[1]/td[1]/font/font/b');
但不会返回任何事情:
我正在使用此鳕鱼对接显示错误
捕获致命错误:类DOMNodeList的对象不可能 在第23行的/home/mysite/curl.php中转换为字符串
<?php
$url="http://www.irimo.ir/farsi/current/index.asp?station=40770";
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$dom = new DomDocument();
@$dom->loadHTML($allcont);
$xpath = new DomXPath($dom);
$return = $xpath->query('/html/body/table[3]/tbody/tr/td/table/tbody/tr/td[2]/p/table/tbody/tr/td/font/div/center/table/tbody/tr[3]/td/font/b');
echo $return;
echo $xpath;
?>
答案 0 :(得分:0)
尝试
$xpath->query('/html/body/table[3]/tbody/tr/td/table/tbody/tr/td[2]/p/table/tbody/tr/td/font/div/center/table/tbody/tr[3]/td/font/b');