2017-12-19 29 views
0

これは私のコードです:php find関数でこの "td"をどのように見つけることができますか?

$post = [ 
     'iatacode' => 'DME', 
    ]; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'http://www.airlinecodes.co.uk/aptcoderes.asp'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); 
    $response = curl_exec($ch); 
    var_export($response); 
    $html5 = str_get_html($response); 
    $elem = $html5->find('td', 5); 
    echo $elem; 

半分答えit'sとして、私の質問を変更する: は、どのように私は唯一の第五「TD」を取得し、全体ではなく、ページをカール表示していますか?

「カーリングしている」ページの6番目の「td」のみを取得して表示するにはどうすればよいですか? 残りを表示したくありません...

+0

よろしくお願いします。完全なコードを表示しますか? – Soolie

+0

ちょうどそれを訂正しました –

+0

コードのすべてです –

答えて

0

'var_export($ response);を削除すると、あなただけが第六TDを表示する

<?php 

$post = [ 
     'iatacode' => 'DME', 
    ]; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'http://www.airlinecodes.co.uk/aptcoderes.asp'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); 
    $response = curl_exec($ch); 
    //var_export($response); 
    $html5 = str_get_html($response); 
    $elem = $html5->find('td', 5); 
    echo $elem; 

?> 
+0

そこにここではsimple_html_domは必要ありませんが、これはXML拡張機能がインストールされているすべてのPHPインストールに組み込まれているDOMDocument :: getElementsByTagNameとほとんど関係ありません。私の意見では、DOMDocument + DOMXpath(どちらもXML拡張機能に組み込まれています)では、simple_html_domは無意味です。 – hanshenrik

+0

@hanshenrikはい、あなたが正しいです、私は古いコードから、私の欠点、いくつかの汚れたコードを持っている – Leo

0

を選択した「TD」を表示されます。

$response = curl_exec($ch); 
echo (@DOMDocument::loadHTML ($response))->getElementsByTagName ("td")->item (6 - 1)->textContent; 

(-1、それは0からカウントを開始するので、これ項目#6が実際にされましたtd#7)

関連する問題