这是我的代码:
$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;
改变我的问题,因为它的答案是: 我如何只获得第5个“td”并且不显示整个卷曲的页面?
如何在页面上只显示第6个“td”并“显示”? 我不希望其余的显示......
答案 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;
?>
答案 1 :(得分:0)
显示第6个td:
$response = curl_exec($ch);
echo (@DOMDocument::loadHTML ( $response ))->getElementsByTagName ( "td" )->item ( 6 - 1 )->textContent;
(-1是因为它从0开始计数,因此第6项实际上是td#7)