PHP刮取在本地主机之外中断
因此,我试图从一个站点中获取一些数据,并使整个脚本在localhost上运行。将其上载到live server,然后返回一个空变量PHP刮取在本地主机之外中断,php,localhost,live,scrape,Php,Localhost,Live,Scrape,因此,我试图从一个站点中获取一些数据,并使整个脚本在localhost上运行。将其上载到live server,然后返回一个空变量 <?php error_reporting(E_ALL); ini_set('display_errors', 1); function getElementByIdAsString($url, $id, $pretty = true) { $doc = new DOMDocument(); $loaded = @$doc->lo
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function getElementByIdAsString($url, $id, $pretty = true) {
$doc = new DOMDocument();
$loaded = @$doc->loadHTMLFile($url);
var_dump($loaded);
if(!$loaded) {
throw new Exception("Failed to load $url");
}
// Obtain the element
$element = $doc->getElementById($id );
if(!$element) {
throw new Exception("An MEMEelement with id $id was not found");
}
if($pretty) {
$doc->formatOutput = true;
}
// Return the string representation of the element
return $doc->saveXML($element);
}
$test = getElementByIdAsString('http://www.google.nl', 'index-banner');
var_dump($test);
?>
我检查了该url,没有id为索引横幅的元素
,因此他们必须在您在localhost上开发后更改DOM。我检查了该url,并且没有id为索引横幅的元素
,因此他们必须在您在localhost上开发后更改DOM。