ローカルの XAMPP インストールでのみ発生する非常に奇妙な問題があります。curl を使用してページからデータを抽出し、それを googlebot として開き、str_get_html()
from simple_html_dom を使用して DOM 要素を抽出するスクリプトがあります。
次のエラーが表示されます。
Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\scraper\facebook.php on line 49
ここに私の関数の上部(この関数は非常に長いので、すべてを投稿するつもりはなく、エラーに投稿するだけです):
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
私のスクリプトはオンライン環境で正常に動作しますが、ローカルで実行されているカールに何か問題があるように見えるため、xampp の問題であると思われます。xamppでcurl
有効にしましたが、phpinfo(); で有効として表示されています。おそらく私のファイアウォールと関係があるのでしょうか?
どんな助けでも大歓迎です、サイモン
編集:
100% は、curl がローカルで実行されていないことです。タイトルを次から変更しました: find() on a non-object in XAMPP using curl and simple_html_dom