X
X
xuxubla2015-07-04 14:16:21
PHP
xuxubla, 2015-07-04 14:16:21

How to avoid errors when using load_file() function in SIMPLE HTML DOM?

I use the Simple HTML DOM library for parsing. The load_file() function is known to work based on file_get_contentns().
There are store pages that load extremely slowly (just some buggy section), resulting in a warning:
Failed to Open Stream: HTTP request failed.
The warning itself is not a problem, let it be. It's just that you can't apply find() to an empty object, it's already "fatal" there.
How to correctly check the validity of the loaded $html content?
I tried this option:

foreach ($item as $link) {
    $html = new simple_html_dom;
    $html -> load_file($link);
    if ($html->root !== NULL) { парсим }
}

root is a property of an object, which is NULL if the object is empty. Until the first error, everything works adequately, but as soon as it encounters an error, it logically skips this page, goes to the next page, but regardless of the nature of this page (it turned out to load or not - this can be seen from the warnings) refuses to parse.
What can be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-07-09
@ntzch

And why not make a recursive function, where if the condition is null, then the function is called again and tries to ask?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question