0
我用下面的代碼來解析從澳大利亞證券交易所表元素:解析從錶鏈接用PHP
<?php
$dom = new DOMDocument();
//load the html
$html = $dom->loadHTMLFile("http://www.asx.com.au/asx/statistics/prevBusDayAnns.do");
//discard white space
$dom->preserveWhiteSpace = false;
//the table by its tag name
$tables = $dom->getElementsByTagName('table');
//get all rows from the table
$rows = $tables->item(0)->getElementsByTagName('tr');
// get each column by tag name
$cols = $rows->item(0)->getElementsByTagName('th');
$row_headers = NULL;
foreach ($cols as $node) {
//print $node->nodeValue."\n";
$row_headers[] = $node->nodeValue;
}
$table = array();
//get all rows from the table
$rows = $tables->item(0)->getElementsByTagName('tr');
foreach ($rows as $row)
{
// get each column by tag name
$cols = $row->getElementsByTagName('td');
$companysymbol = $cols->item(0)->nodeValue;
$pubtime = $cols->item(1)->nodeValue;
$newstitle = $cols->item(3)->nodeValue;
$row = array();
echo $companysymbol . '<br>';
echo $pubtime . '<br>';
echo $newstitle . '<br><br>';
}
?>
的代碼工作正常,但除了呼應$ companysymbol,$ pubtime和$ newstitle我想回顯表格內的鏈接(PDF鏈接)。有人能告訴我如何?
在此先感謝您的幫助!
謝謝回答,但不幸的是您的解決方案將回聲單詞「PDF」,而不是鏈接本身(HREF內標籤)。 – Tim
完美的作品!感謝1000次! – Tim