как использовать простой html dom получить внутренний html

У меня есть код для отслеживания результатов таблицы html с этого сайта http://www.jne.co.id/tarif.php

я пытаюсь создать из моего локального хоста этот код:

<?php include_once("simple_html_dom.php");


if($_POST){

    //extract data from the post
    //set POST variables
    $url = 'http://www.jne.co.id/tarif.php';
    $fields = array(
        'origin_code' => urlencode($_POST['origin_code']),
        'dest_code' => urlencode($_POST['dest_code']),
        'weight' => urlencode($_POST['weight']),
        'g-recaptcha-response' => urlencode($_POST['g-recaptcha-response']),
    );

    $fields_string = '';
    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string, '&');

    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //execute post
    $result = curl_exec($ch);   

    $string = $result;//htmlentities($result);

    //close connection
    curl_close($ch);

    // Create a DOM object
    $html_base = new simple_html_dom();
    // Load HTML from a string
    $html_base->load($string);

    $str = $html_base->find('.tracking');
echo $str;

    $html_base->clear(); 
    unset($html_base);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form class="check validate" action='' method='post' style='float:none;max-height:none;'>
<div class="row">
<label>
<input type='hidden' name='origin_code' value="CGK10000" class='required'>
<input type="text" name='origin_label' placeholder="Origin" class='autocomplete required' data-url='lib/origin.php' data-origin="JAKARTA" value="JAKARTA">
<br>Origin Shipment
</label>
<label>
<input type='hidden' name='dest_code' value="BDO10000" class='required'>
<input type="text" name='dest_label' placeholder="Destination"     class='autocomplete required' data-url='lib/dest.php' data-origin="BANDUNG" value="BANDUNG">
<br>Destination Shipment
</label>
<label>
<input name="weight" type="text" placeholder="1" style="width:30px; text-align:center" value="1" class='required number'>
<br>Weight(Kg)
</label>
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="6LeyjxETAAAAAE5qSotpy40_cG31GyRm-VSBQaWU" style="margin:10px 0px;"></div>
<button class="btn red">check</button>
</div>
</form>
</body>
</html>

мне нужно получить таблицу html с классом "отслеживание table_style", см. это изображение

Изображение

РЕДАКТИРОВАТЬ: мне просто нужно получить html <table> с отслеживанием классов, а не строку внутри html. результат как этот html:

<table width="100%" border="0" class="table_style tracking">
<thead>
<tr>
<td>Nama Layanan</td>
<td align="center">Jenis Kiriman</td>
<td>Tarif </td>
<td>ETD(Estimates Days) </td>
</tr>
</thead>
<tbody><tr>
<td>OKE</td>
<td align="center">Dokumen / Paket</td>
<td>Rp. 10.000</td>
<td>2 - 3 D</td>
</tr><tr>
<td>REG</td>
<td align="center">Dokumen / Paket</td>
<td>Rp. 11.000</td>
<td>1 - 2 D</td>
</tr><tr>
<td>YES</td>
<td align="center">Dokumen / Paket</td>
<td>Rp. 22.000</td>
<td>1 - 1 D</td>
</tr><tr>
<td>SPS</td>
<td align="center">Dokumen / Paket</td>
<td>Rp. 403.000</td>
<td> </td>
</tr></tbody>
</table>

person husen    schedule 22.02.2016    source источник
comment
вау, ты можешь обойти recaptcha?   -  person Kevin    schedule 22.02.2016
comment
я не знаю, но я так думаю. просто отправьте g-recaptcha-response на curl, и я получу результат. :D   -  person husen    schedule 22.02.2016
comment
Это может быть полезно, если вы не используете метод DOM, что, вероятно, является лучшим способом. Заголовок stackoverflow.com/questions/34834038/   -  person Steve    schedule 22.02.2016


Ответы (1)


Попробуйте использовать это:

http://sourceforge.net/projects/simplehtmldom/

Например:

$items = str_get_html($html);
$count = 0;
$country = $items->find('.category-label span', 0)->text(); // first element by index 0
person Artemiy StagnantIce Alexeew    schedule 22.02.2016