Placeholder Placeholder - 2 years ago 325
PHP Question

PHP Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in

I am currently using simple_html_dom.php and this is the first time I think I have stumbled into this problem and I am not sure the solution (been working on it for almost two hours now.)

Fatal error: Call to a member function find() on boolean in /m/ on line 12

Above is the error that is displaying on our page when we try and scrape a
element of the requested site view the code below.

$page = (isset($_GET['p'])&&$_GET['p']!=0) ? (int) $_GET['p'] : '';
$html = file_get_html('');
foreach($html->find('a') as $element) {
print '<br><br>';
echo $url = ''.$element->href;
$html2 = file_get_html($url);
print '<br>';

$link = $html2->find('.cont_display a',0);
print $link = $link->href;

Now I know for sure that there's
<a href""></a>
tags on the site we're looking for how ever it keeps returning that error no matter what I change..

line 75 in simple_html_dom.php just says the following.

function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
// We DO force the tags to be terminated.
$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
// For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done.
$contents = file_get_contents($url, $use_include_path, $context, $offset);
// Paperg - use our own mechanism for getting the contents as we want to control the timeout.
//$contents = retrieve_url_contents($url);
if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
return false;
// The second parameter can force the selectors to all be lowercase.
$dom->load($contents, $lowercase, $stripRN);
return $dom;

WARNING: Don't view the content destination unless you have an ad-block you will get loads of popups.

EDIT: Even after changing the url it returns the same issue

Fatal error: Call to a member function find() on boolean in /m/ on line 18

  • I think I have figured something out though, when loading the page it creates a random div which triggers the popup and unless you delete that div or trigger it the other elements don't appear.. could this be what's causing our issue?

Answer Source

When I open your link (in Chrome incognito mode, with adblocker enabled) it really does give a 404. The page is not found, so your error is expected.

It appears you are missing a trailing slash. Add a final slash to your URL and it works.


$html = file_get_html(''.$page.'/');

If you look at view-source: in Chrome, you'll see the html code that I believe you expect to see.

I confirmed that file_get_contents(''); is successfully retrieving the HTML for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download