simple dom php 404 error

Asked

Viewed 115 times

0

I have the following code:

<?php

include './simple_html_dom.php';

//Este link existe
$teste = new simple_html_dom("http://www.btolinux.com.br/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
    $teste->find("html");
}

//Aqui estou forçando um erro 404.
$teste = new simple_html_dom("http://www.btolinux.com.br/error/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
    $teste->find("html");
}

//A partir de agora todo objeto que eu criar vai estar com erro
$teste = new simple_html_dom("http://www.btolinux.com.br/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
    $teste->find("html");
}

?>

Guys, I’ve tried several ways I’ve used unset($test) and nothing happens, I’ve tried to rewrite using:

$teste = new simple_html_dom();
$teste->load_file("http://www.btolinux.com.br/");

OR

$teste = file_get_html("http://www.btolinux.com.br/");

And it only gets worse...

Basically I believe it is an object persistence error in memory, since the error that appears in the 3rd object is:

Fatal error: Call to a Member Function find() on a non-object in /var/www/html/Crawler/simple_html_dom.php on line 1113

Well, I’ve tried everything, but I can’t find an answer...

for those who try to lower their class simple_html_dom

  • Post the class being included or a link to it. At first I would venture a guess that whoever created it used a static property where it shouldn’t.

  • Oops! I edited the text pointing the link to the class... I forgot to put.

2 answers

2

pdonatilio solved the problem by not using the class when there was no file, but this solves part of the problem. The central issue is that the class generates a fatal error and will no longer run to create new instances, so the new objects will all be in error. Not that the solution is wrong, but I think it should be investigated.

For me it is a class bug, because a class should escape from simple errors like file not found. In this case, you should look at List of simple-dom-parser bugs if there is no report of the bug and report if there is not. The error may also be in trying to escape, php version problem, etc., have to talk like the people who developed, otherwise you turn a corner on this specific problem, but it comes back later for another reason.

  • Oops, pal. I agree 100% with what you said. I will contact the staff who developed the class and seek together with them a better and more elegant solution.

0

I solved the problem by making the following change:

Replace that:

$teste = new simple_html_dom("http://www.btolinux.com.br/error/");
echo $teste->original_size."<br>";
if($teste->original_size !== 0){
   $teste->find("html");
}

For this reason

$html = @file_get_contents("http://www.btolinux.com.br/error/");
if ($html!='') {
   $teste = new simple_html_dom($html);
   echo 'SIZE: '.$teste->original_size."<br>";
   $teste->find("html")
}

And it worked out... Well, good evening, folks... and until next time...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.