获取 DHL 跟踪状态

get DHL tracking statuses

请帮我弄清楚我应该使用什么 PHP API 或 PHP 脚本从 DHL the shipment statuses 获取,只有 DHL Tracking Codes 提供由物流公司负责从电子商务网站运送我们的订单。我的任务是创建一个 PHP CronJob 代码,用于检查和注册 DHL Tracking Shipping 的状态,以便在后端报告中使用它们。

如果有任何建议可以帮助我找到正确的方向,我将不胜感激。

我仍在寻找完成任务的正确方法。所以,到目前为止,除了解析 DHL 跟踪网页之外,我没有看到其他方法,考虑到只有跟踪号码可用,这似乎不足以将它们用于某些 API。 DHL API 需要登录凭据、密钥等...但是,我当前的解析代码可能对寻找类似解决方案的人有用。只需将您的跟踪代码和 运行 代码包含在您的本地主机中,甚至 http://phpfiddle.org/:

$tracking_array=Array('000000000000', '1111111111111'); // Tracking Codes

function create_track_url($track)
{
    $separator = '%2C+';
    $count = count($track);
    $url = '';
    if ($count < 2 && $count > 0){
       $url =  $track[0];
    }else if ($count >1){
        foreach ($track as $k => $v)
        {
          $sep = ($count-2);
            if ($k > $sep){
                $separator ='';
            }
          $url .=  $v.$separator;
        }
    }


   return $url; 
}
//load the html  
$dom = new DOMDocument(); 
$html = $dom->loadHTMLFile("https://nolp.dhl.de/nextt-online-public/en/search?piececode=".create_track_url($tracking_array));  

  //discard white space   
$dom->preserveWhiteSpace = false;  
  //the table by its tag name  


$xpath = new DOMXpath($dom);

$expression = './/h2[contains(@class, "panel-title")]';

$track_codes =array();
foreach ($xpath->evaluate($expression) as $div) {
  $track_codes[]= preg_replace( '/[^0-9]/', '', $div->nodeValue );
}

$tables = $dom->getElementsByTagName('table'); 
$table = array();
foreach($track_codes as $key => $val)

{
    //get all rows from the table  
$rows = $tables->item($key)->getElementsByTagName('tr');   
  // get each column by tag name  
$cols = $rows->item($key)->getElementsByTagName('th');   
$row_headers = NULL;
foreach ($cols as $node) {
    //print $node->nodeValue."\n";   
    $row_headers[] = $node->nodeValue;
}  

  //get all rows from the table  
$rows = $tables->item(0)->getElementsByTagName('tr');   
foreach ($rows as $row)   
{   
   // get each column by tag name  
    $cols = $row->getElementsByTagName('td');   
    $row = array();
    $i=0;
    foreach ($cols as $node) {
        # code...
        //print $node->nodeValue."\n";   
        if($row_headers==NULL)
            $row[] = $node->nodeValue;
        else
            $row[$row_headers[$i]] = $node->nodeValue;
        $i++;
    }   
    $table[$val][] = $row;
}
}   
print '<pre>';
print_r($table);