我正在尝试从网页中的两行获取数据,每行包含两行。经过一些阅读后,我尝试了以下代码;
<?PHP
require('simple_html_dom.php');
$ch = curl_init();
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$target_url = 'http://www.boz.zm/(S(0m5hxtuuoex4xqjkzrpbsh55))/Startpage.aspx';
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$html = curl_exec($ch);
if (!$html)
{
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
else
{
echo "<br> Think the page was nabbed";
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$tableData = array();
foreach($xpath->query('//table[@id="_ctl0_zmain_Dg_ExchangeRates"]/tr[position()<5]') as $node)
{
$rowData = array();
foreach($xpath->query('td', $node) as $cell)
{
$rowdat = $cell->textContent;
$rowData[] = $rowdat;
}
$tableDate[]=$rowData;
}
print_r($tableData);
}
?>
仅返回一个空数组。 我想将每行的值放在一个多维数组中,以便我可以轻松地使用它们。关于我如何能够完成这项任务的任何想法,即使它与我试图做的不同的方法我也不介意。在此先感谢。
答案 0 :(得分:0)
这只是一种错误的写法:你写的是:$tableDate[]=$rowData;
而不是$tableData[]=$rowData;