Search code examples
phpsimple-html-dom

PHP Simple HTML DOM Parser some pages issue


I have a code for read all inputs in a form.

The code works in my demo page an others, but not work in some pages. For the example issue:

facebook:

$url = 'https://www.facebook.com';

$html = file_get_html($url);
$post = $html->find('form[id=reg]'); //id for the register facebook page

print_r($post);

Print an empty array.

Functional example:

$url = 'http://www.monografias.com/usuario/registro';

$html = file_get_html($url);

$post = $html->find('form[name=myform]');
print_r($post);

Print a form content


Solution

  • Facebook won't give you registration form directly, it will only respond with basic html, and the rest will be created with javascript. see for yourself

    $url = 'https://www.facebook.com';
    $html = file_get_html($url);
    echo htmlspecialchars($html);
    

    there is no form with "reg" ID in the html they send you.