2016-11-24 87 views
0

我的頭很疼。 我最近做了一個網站,並使用DOMXpath。它與URL完美結合。 現在我想從同一個文件夾中的html文件中獲取東西。突然之間,最簡單的事情成爲最多的問題。 我甚至不知道爲什麼它不能使用文件而不使用URL。 以下是文件:DOMXpath什麼也沒有返回

error_reporting(0); 
include_once "db_config.php"; 
$file = $DOCUMENT_ROOT. "today.html"; 
$doc = new DOMDocument(); 
$doc->loadHTMLFile($file); 
$xpath = new DOMXpath($doc); 
$elements = $xpath->query("/html/body/table/tbody/tr/td[1]"); 
    foreach ($elements as $element) { 
    $nodes = $element->childNodes; 
    foreach ($nodes as $node) { 
     $name = $node->nodeValue; 
     echo $name; 
    } 
} 

這裏是today.html:

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>aaaaa</title> 
</head> 

<body> 
<table> 
<tr> 
    <td class="col2 centertd">ΑΥΣΛ</td> 
    <td class="col3 centertd">10:50</td> 
    <td class="col4 centertd">1985</td> 
    <td class="col5 centertd">3,30</td> 
</tr> 
</table> 
</body> 
</html> 

請什麼能幫上忙。 非常感謝你的時間。

+0

從您的XPath中刪除tbody。 – Markus

+0

哇!我的腦袋受傷了,這是關於那個屍體的...... 我無法描述我是多麼的感恩...... – user3921906

回答