我需要从一个网页中提取一些信息,这是一个审讯的结果(这是跟踪一次运输的结果,因此每次我想询问并获得的页面时信息来自结果,结果是一些审讯(
这是一个示例:
https://www.sda.it/wps/portal/Servizi_online/ricerca_spedizioni?locale=it&tracing.letteraVettura=3872809292532
现在,我想从此结果页面中获取和复制的信息在此处包含:
<div class="col-md-6 col-xs-8">
<span data-bind="text: descrizioneTracing"
class="delivery-status"></span>
</div>
但是在HTML视图中,我看不到结果。我需要提取,在这种情况下是:&quotla spedizione e'Stata consegnata'
我有一些想法并试图使用这种方式,
$url = file_get_contents('https://www.sda.it/wps/portal/Servizi_online/ricerca_spedizioni?locale=it&tracing.letteraVettura='.$numldv);
$dom = new DomDocument();
$dom->load($url);
$finder = new DomXPath($dom);
$classname="delivery-status";
$nodes = $finder->query("//*[contains(@class, '$classname')]");
我不知道是否真的是好方向,以及如何作为字符串打印$节点的结果,
之后,我只需要
,我会更加具体 data-bind="text: descrizioneTracing"
但是目前我还不知道该怎么做。
有任何建议或帮助?
谢谢。
尝试一下,但是当前,您的网站URL返回一个空字符串
<?php
$html = file_get_contents('https://www.sda.it/wps/portal/Servizi_online/ricerca_spedizioni?locale=it&tracing.letteraVettura=3872809292532'); //get the html returned from the following url
$pokemon_doc = new DOMDocument();
libxml_use_internal_errors(TRUE); //disable libxml errors
if(!empty($html)){ //if any html is actually returned
$pokemon_doc->loadHTML($html);
libxml_clear_errors(); //remove errors for yucky html
$pokemon_xpath = new DOMXPath($pokemon_doc);
//get all the h2's with an id
$pokemon_row = $pokemon_xpath->query('span[data-bind="text: descrizioneTracing"]');
echo json_encode($html);die;
if($pokemon_row->length > 0){
foreach($pokemon_row as $row){
echo $row->nodeValue . "<br/>";
}
}
}
?>