Using curl in XAMPP local enviroment not running

ぃ、小莉子 提交于 2019-12-24 09:41:17

问题


I have got quite a strange issue that is only occurring on my local XAMPP install. I have a script to extract data from a page using curl to open it as googlebot then using str_get_html() from simple_html_dom to extract DOM elements.

I am getting the following error: Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\scraper\facebook.php on line 49

Top part of my function here (this function is very long so not going to post it all, will only post to the error):

function get_facebook_data($link)
{
    $username    = "";
    $title       = "";
    $location    = "";
    $email       = "";
    $description = "";
    $userAgent   = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
    $url         = get_facebook_page($link);
// THE ABOVE VARIABLE IS A VALID URL IF I ECHO IT WILL GIVE: http://www.facebook.com/pages/The-Pencil-Test/179417698765073?id=179417698765073&sk=info BEFORE GIVING THE ERROR
    $ch          = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    $html     = curl_exec($ch);
    $cache    = $html;
    $html2    = str_get_html($cache);
    $data     = $html2->find("span.uiButtonText");
//THE LINE ABOVE IS THROWING THE ERROR

My script works fine in an online enviroment which makes me believe it is an xampp issue, by the looks of things something wrong with curl running locally. I have got curl enabled in xampp and it is showing as enabled in phpinfo(); Could it be something to do with my firewall perhaps?

Any help greatly appreciated, Simon

edit:

100% it is that curl is not running locally, changed title from: find() on a non-object in XAMPP using curl and simple_html_dom

来源:https://stackoverflow.com/questions/18916462/using-curl-in-xampp-local-enviroment-not-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!