问题
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