2017-04-13 160 views
-3

我使用下面的代碼,但從鏈接我不能解析所有股票數據的值。任何人都可以幫助我嗎?不能用PHP解析網頁簡單的HTML DOM解析器

<?php 
// Include the library 
include('simple_html_dom.php'); 

// Retrieve the DOM from a given URL 
$html = file_get_html('http://www.dsebd.org/dseX_share.php'); 


// Extract all text from a given cell 
echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>'; 
+0

您是否收到錯誤消息?你可以再詳細一點嗎? – Difster

+0

請閱讀[如何創建最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)。你需要告訴你想要解析哪些列。有很多列。您還需要提供您收到的任何錯誤消息。別指望別人爲你編寫完整的代碼。所以,試着更具體。 –

+0

我只是想重寫這一行來解析表$ html-> find('td [align =「center」]',1) –

回答

-1
<?php 

ini_set('display_errors', 1); 
include_once('simple_html_dom.php'); 

$html = file_get_html('http://www.dsebd.org/dseX_share.php'); 
$table = $html->find('table', 5); 

$rowData = array(); 

foreach ($table->find('tr') as $row) 
{ 
    foreach ($row->find('td') as $cell) 
    { 
     $flight = array(); 
     $cell->plaintext= preg_replace('/<\/[\w]+>/',"",$cell->plaintext); 
     $flight[] = array_map('trim', preg_split("@(\&nbsp;)[email protected]", $cell->plaintext)); 
    } 
    $rowData=array_merge($rowData,$flight); 
} 
print '<pre>'; 
print_r($rowData); 
print '</pre>'; 
?> 
+0

非常感謝你的工作。 –

+0

@FindyMob歡迎... :) –