PHP脚本
<?php
error_reporting(E_all);
ini_set('display_errors', 1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.gloryfeed.com/scale405.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
if($output == FALSE){
echo "cURL Error: " . curl_error($ch);
}
$dom = new DOMDocument();
$dom->loadHTML( $output );
$test = $dom->saveHTML($dom->getElementById('displayedWeight'));
//$dom->getElementById('displayedWeight')
curl_close($ch);
echo "Your 'Weight' is: " . $test . "\n";
//print_r($output);
?>
HTML PAGE
<div class="weightDisplay" id="displayedWeight">0</div>
这是我想要获得的变量。该页面有一个更新功能,可以更新div weightDisplayed。但是当curl抓取页面并且DomDocument解析数据时,它只是接收默认值0.有没有办法获取更新的值?
答案 0 :(得分:0)
这会将信息输入数组;
<?php
error_reporting(E_all);
ini_set('display_errors', 1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.gloryfeed.com/get_var.cgi?index=99');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
if($output == FALSE){
echo "cURL Error: " . curl_error($ch);
}
$test = json_decode($output,true);
print_r($test);
echo('<br>');
$test = explode('|',$test['value']);
print_r($test);