2016-08-23 78 views
1

我想从其他网站页面中动态加载表格数据。 我使用Php和简单的Html Dom搜刮很多搜索后没有找到任何解决方案如何从网页上抓取动态数据?或者有另一种方法可以做到这一点?Scrape Div的内容通过Ajax使用Simple Html动态加载动态

我必须从这个url->https://fantasy.premierleague.com/a/leagues/standings/313/classic刮表数据。

我正在使用下面的代码来做到这一点。

$url = "https://fantasy.premierleague.com/a/leagues/standings/313/classic"; 
$html = file_get_html($url); 
$html->find('div#ismr-classic-standings'); 
foreach($html->find('table.ism-table--standings tr') as $row){ 
//But count($row)=0 due to late loading html in table. 
} 
+0

尽管表格的数据是动态的,但DOM结构应该是相同的。它是一样的吗?如果是这样,那么你可以通过使用它的类或html DOM结构来查找。你可以添加一些代码,以便我们更好地理解。 –

+0

添加一些代码或示例,以便我们可以走得更远! –

+0

你好,@Mit.agile代码加上 –

回答

1

您的页面正在调用另一个链接并检索JSON数据;试试这个代码:

include "simple_html_dom.php"; 
$MyWebsite = 'https://fantasy.premierleague.com/drf/leagues-classic-standings/313?phase=1&le-page=1&ls-page=1'; 
$html = file_get_html($MyWebsite); 
$JSON_value = json_decode($html, true); 
$results = $JSON_value['standings']['results']; 

foreach($results as $result) { 
    echo $result['entry_name'] . '->' . $result['event_total'] . '<br/>'; 
}