【发布时间】:2013-08-26 17:56:42
【问题描述】:
我正在使用简单的 HTML DOM 解析器 - http://simplehtmldom.sourceforge.net/manual.htm 我正在尝试从记分牌页面中抓取一些数据。下面的示例展示了我拉取“Akron Rushing”表的 HTML。
在$tr->find('td', 0) 的第一列中,有一个超链接。如何提取此超链接?使用$tr->find('td', 0')->find('a') 似乎不起作用。
另外:我可以为每张桌子写条件(传球、冲球、接球等),但有没有更有效的方法呢?我对这方面的想法持开放态度。
include('simple_html_dom.php');
$html = file_get_html('http://espn.go.com/ncf/boxscore?gameId=322432006');
$teamA['rushing'] = $html->find('table.mod-data',5);
foreach ($teamA as $type=>$data) {
switch ($type) {
# Rushing Table
case "rushing":
foreach ($data->find('tr') as $tr) {
echo $tr->find('td', 0); // First TD column (Player Name)
echo $tr->find('td', 1); // Second TD Column (Carries)
echo $tr->find('td', 2); // Third TD Column (Yards)
echo $tr->find('td', 3); // Fourth TD Column (AVG)
echo $tr->find('td', 4); // Fifth TD Column (TDs)
echo $tr->find('td', 5); // Sixth TD Column (LGs)
echo "<hr />";
}
}
}
【问题讨论】:
标签: php dom simple-html-dom tree-traversal