我正在从事这个项目:
<?php
$curl = curl_init("https://www.timeanddate.com/worldclock/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($curl);
if(!empty($curl)){
$thispage = new DOMDocument;
libxml_use_internal_errors(true);
$thispage->loadHTML($html);
libxml_clear_errors();
$xpath = new DOMXPath($thispage);
$status = $xpath->evaluate('string(//*[@id="p36"])');
echo $status;
}
Curl连接到网站timeanddate.com
,并从对象//*[@id="p36"]
(xpath)读取数据。
如何从两个对象而不是一个对象读取数据?
答案 0 :(得分:0)
好的,我已经发现两个变量是必需的:
$xpath = new DOMXPath($thispage);
$status = $xpath->evaluate('string(//*[@id="p36"])'); //first object
$xpath2 = new DOMXPath($thispage);
$status2 = $xpath2->evaluate('string(//*[@id="p28"])'); //second object
echo $status;
echo $status2;