2014-09-05 138 views
0

請幫我改一下我的代碼選擇器。用php和ganon解析html

我嘗試從http://www.plati.ru/asp/seller.asp?id_s=119777

頁得到sellen名稱這是必須AMEDIA,但我不能得到它。

這是我的代碼

$result = curl_exec($ch); 
curl_close($ch); 
$html = str_get_dom($result); 

foreach ($html('table tr td tr td') as $element) { 
    $seller_name = $element->getPlainText(); 
} 
+0

也許這將是:body table tbody tr td table tbody tr td? – 2014-09-05 13:29:10

回答

0

你可以嘗試以下方法,讓我知道,如果你還有什麼困難,

include "ganon.php"; 
$shopUrl = "http://www.plati.ru/asp/seller.asp?id_s=119777"; 
$html = file_get_dom($shopUrl); 
echo $html('table',9)->getPlainText(); 
+0

謝謝,你很喜歡 – bigjoy10 2014-09-05 14:19:27

+0

它是我的快樂朋友。快樂的編碼 – Pundit 2014-09-05 14:21:29

0

可以使用DomDocument這樣的代碼來獲取TD值:

<?php 
    header('Content-Type: text/html; charset=utf-8'); 

    $DOM = new DOMDocument; 
    @$DOM->loadHTMLFile('http://www.plati.ru/asp/seller.asp?id_s=119777'); 

    $tables = $DOM->getElementsByTagName('table');//->item(10); 
    $table = $tables->item(9); 
    $cells = $table->getElementsByTagName('td'); 
    $cell = $cells->item(0); 
    echo $cell->textContent; 
?> 

拆分$cell->textContent使用spa CES。