因此,一个非常有帮助的人帮助我在Stackoverflow上获得了这么多,但是我需要将他的代码从HTMl转换为一个URL来刮擦我尝试了一遍又一遍,并且一直打错了任何想法?将html转换为url scraper
function getElementByIdAsString($html, $id, $pretty = true) {
$doc = new DOMDocument();
@$doc->loadHTML($html);
if(!$doc) {
throw new Exception("Failed to load $url");
}
$element = $doc->getElementById($id);
if(!$element) {
throw new Exception("An element with id $id was not found");
}
// get all object tags
$objects = $element->getElementsByTagName('object'); // return node list
// take the the value of the data attribute from the first object tag
$data = $objects->item(0)->getAttributeNode('data')->value;
// cut away the unnecessary parts and return the info
return substr($data, strpos($data, '=')+1);
}
// call it:
$finalcontent = getElementByIdAsString($html, 'mainclass');
print_r ($finalcontent);
你提到的错误......它们是什么? – camelCase
它只是空白。有没有更好的方法让我得到错误?所有这一切都是新的 – Jamie
我简单地试图放置一个URL来抓取,而不是堆栈溢出的人做的$ html示例 – Jamie