我正在尝试使用php从xpath/html中获取文本,但没有成功。有什么想法。
例如: https://safeweb.norton.com/report/show?url=google.com
我的xpath(我已经仔细检查过了)
//*[@id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b
我想要在这里出现一个结果<div> result </div>
,使用php
以下是我的代码:
<?php
public function getNortonSafe($domain)
{
try
{
$callback_url = "https://safeweb.norton.com/report/show?url=google.com"; //. $domain;
$curl_response = $this->curl->get($callback_url);
if ($curl_response->headers['Status-Code'] == "200") {
libxml_use_internal_errors(TRUE);
$this->dom_doc->loadHTML($curl_response);
libxml_use_internal_errors(FALSE);
$xpath = new DOMXPath($this->dom_doc);
$tmp = $xpath->query('//*[@id="bodyContent"]/div/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/b')->item(0)->textContent);
$tmp = explode(' ', trim($tmp));
$norton_site_test = str_replace(",", "", $tmp[0]);
} else {
$norton_site_test = "0";
}
$response = array(
'status' => 'success',
'data' => array(
'norton_site_test' => filter_var($norton_site_test, FILTER_SANITIZE_STRING)
)
);
}
catch (Exception $e)
{
$response = array(
'status' => 'error',
'msg' => $e->getMessage()
);
}
return $response;
}
?>
HTML
<body>
<p id="norton_site_test"> result-text-here </p>
</body>