2016-08-23 76 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/>'; 
}