0
我想湊這個網址XPath的出現誤導輸出簡單的HTML DOM
http://www.gosugamers.net/counterstrike/news/archive
我使用XPath的幫助來創建以下路徑每一行:
//div[class='content']/table[@class='simple gamelist medium']/tbody/tr
這應該打印tbody中的每一行,但是當我在簡單的html dom中嘗試此操作時,它會返回帶有標題,日期和註釋的thead。它如何不像xpath助手那樣返回tbody呢?
include('simple_html_dom.php');
function getHTML($url,$timeout)
{
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
return @curl_exec($ch);
}
$html = str_get_html(getHTML("http://www.gosugamers.net/counterstrike/news/archive",10));
$table = $html->find("//div[class='content']/table[@class='simple gamelist medium']/tbody/tr",0);
echo $table;
好的,但我如何獲得第二排?我嘗試過[2],但似乎沒有工作 – 2015-04-03 18:10:41
你從//[div class ='content']/table [@ class ='simple gamelist medium']/tbody/tr [2] '?沒有結果? – joemfb 2015-04-03 18:11:59
沒有結果!奇怪的是 – 2015-04-03 18:14:47