Sửa lỗi Simple html dom file_get_html not working - is there any workaround? (ok)

https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround

Đã ok

<?php
include('simple_html_dom.php');
// Report all PHP errors (see changelog)
$base = 'https://mediamart.vn';

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);

// Create a DOM object
$html_base = new simple_html_dom();
// Load HTML from a string
$html_base->load($str);

//get all category links
foreach($html_base->find('a') as $element) {
    echo "<pre>";
    print_r( $element->href );
    echo "</pre>";
}

$html_base->clear(); 
unset($html_base);

?>

98

I have the above code and I'm trying to get certain elements of the Play Store page but it isn't returning anything. Is it possible that certain PHP functions might be disabled on the server to stop that?

The above code works perfectly on other sites.

Is there any workaround?phparrow-up-right html-parsingarrow-up-right file-get-contentsarrow-up-right simple-html-domarrow-up-rightsharearrow-up-right improve this questionarrow-up-right follow edited Mar 31 '14 at 23:45arrow-up-rightarrow-up-rightJasonMArcherarrow-up-right11.2k1111 gold badges5151 silver badges5050 bronze badgesasked Sep 6 '13 at 22:20arrow-up-rightAltinarrow-up-right1,41522 gold badges2020 silver badges4242 bronze badges

add a commentarrow-up-right

4 Answers

Activearrow-up-rightOldestarrow-up-rightVotesarrow-up-right35

As I said, your example is working fine for me... But try this way using curl instead:

It gets all the links as expected:

enter image description here

And make sure you have php_openssl and php_curl installed...sharearrow-up-right improve this answerarrow-up-right follow answered Sep 7 '13 at 0:45arrow-up-rightEnissayarrow-up-right4,64733 gold badges2424 silver badges4747 bronze badges

add a commentarrow-up-right3

remove the semicolon from php.ini and restart Apache server to enable php module configuration

sharearrow-up-right improve this answerarrow-up-right follow answered Aug 23 '16 at 2:05arrow-up-rightChitsai Yeharrow-up-right4611 bronze badgeadd a commentarrow-up-right2

You must set "allow_url_fopen" as TRUE in "php.ini" to allow accessing files via HTTP or FTP. Some hosting venders disable PHP's "allow_url_fopen" flag for security issues.sharearrow-up-right improve this answerarrow-up-right follow answered Jan 7 '15 at 23:01arrow-up-rightshahilarrow-up-right72377 silver badges1717 bronze badgesadd a commentarrow-up-right1

DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseStartTag: misplaced THIS IS URL : http://www.annauniv.edu/cgi-bin/result/cgrade.pl?regno=11210104001arrow-up-right

Last updated

Was this helpful?