我试图从http://www.nhl.com/ice/standings.htm?season=20112012&type=LEA抓取表,并将其存储到服务器上的MySQL数据库中。使用下面,我能够准确地复制网站,但我不确定如何提取表格。下列代码:
任何想法?
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data('http://www.nhl.com/ice/standings.htm?season=20112012&type=LEA');
echo $returned_content;
更新:
$html = file_get_html('http://www.nhl.com/ice/standings.htm?season=20112012&type=LEA');
$e = $html->find("table", 2);
echo($e);
这段代码的工作原理,张贴像我需要的一个表。但现在我很好奇,我将如何去剥离所有不必要的链接/格式和保存到数据库?
尝试使用这个库http://simplehtmldom.sourceforge.net/
在谷歌电子表格,我所有的importhtml
函数nhl.com不工作今年。我认为他们(出于某种原因)阻止用户抓取他们的数据。