PHP   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php – 简单的html dom file_get_html无法正常工作 – 是否有任何解决方法?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP
// Report all PHP errors (see changelog)
error_reporTing(E_ALL);

include('inc/simple_html_dom.PHP');

    //base url
    $base = 'https://play.google.com/store/apps';

    //home page HTML
    $html_base = file_get_html( $base );

    //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);

?>

我有上面的代码,我正在尝试获取Play商店页面的某些元素,但它没有返回任何内容.是否有可能在服务器上禁用某些PHP功能来阻止它?

上面的代码在其他网站上完美运行.

有没有解决方法

@H_616_10@
正如我所说,你的例子对我来说很好……但是尝试使用curl这样做:
//base url
$base = 'https://play.google.com/store/apps';

$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,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);

它按预期获得所有链接

并确保安装了PHP_openssl和php_curl

大佬总结

以上是大佬教程为你收集整理的php – 简单的html dom file_get_html无法正常工作 – 是否有任何解决方法?全部内容,希望文章能够帮你解决php – 简单的html dom file_get_html无法正常工作 – 是否有任何解决方法?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。