【发布时间】:2013-06-07 08:28:39
【问题描述】:
我想从一些 Facebook 公共页面(如电话、电子邮件、网站等)中抓取联系信息,这些页面列在任何 facebook 页面的“关于”部分的“联系信息”标题下方。
我正在使用 SIMPLE_HTML_DOM 解析器进行抓取。
问题是当我使用该函数时,echo $html = file_get_html($url); 它没有显示任何内容。
另外,当我使用 curl 例如echo $html=str_get_html($myUrl); 它正在为我显示 html,在页面顶部还有一些 http 路径信息文本,但是当我看到此页面的源代码时,它包含 json 代码,在一些 html 注释代码中具有 <h4>contact info</h4>。
现在,当我定位包含<h4> 和下面其他信息的 div 时,
喜欢,$Contact_info = $html->find('div #pagelet_contact_info')->plaintext;
它不会为我返回任何东西并给我通知,
注意:尝试在第 18 行获取 D:\xampp\htdocs\scoopon_deals\test.php 中非对象的属性
因为它没有找到我调用的 html 返回的特定 div,所以我什至对页面中的每个标签和 href 等都进行了尝试,但没有找到。 ....
我的代码正在跟踪!
include('connect.php'); 包括('simple_html_dom.php');
$url = "http://www.facebook.com/ScooponTravel/info";
$myUrl =curl_grab($url,"https://www.google.com", "", "false", "null", "false");
echo $html=str_get_html($myUrl);
//echo $html = file_get_html($url);
if(is_object($html)){
echo "helloooo";echo '<br>';
$Contact_info = $html->find('div #pagelet_contact_info')->plaintext;
//print_r($deal_title);
echo "Yesss";
}
////// curl function
function curl_grab($url,$ref_url,$data,$login,$proxy,$proxystatus){
if($login == 'true') {
if($fp = fopen("cookie.txt", "w")){
fclose($fp);
}else{echo "+++++++++++++++++++++++++++++++++++++++++";}
}
// global $charam;
$charam = curl_init();
//curl_setopt($charam, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
//curl_setopt($charam, CURLOPT_COOKIEJAR, "cookie.txt");
//curl_setopt($charam, CURLOPT_COOKIEFILE, "cookie.txt");
//curl_setopt($charam, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
//curl_setopt($charam, CURLOPT_TIMEOUT, 440);
curl_setopt($charam, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'true') {
curl_setopt($charam, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($charam, CURLOPT_PROXY, $proxy);
}
curl_setopt($charam, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($charam, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($charam, CURLOPT_URL, $url);
curl_setopt($charam, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($charam, CURLOPT_REFERER, $ref_url);
curl_setopt($charam, CURLOPT_HEADER, TRUE);
curl_setopt($charam, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($charam, CURLOPT_FOLLOWLOCATION, TRUE);
// curl_setopt($charam, CURLOPT_POST, TRUE);
// curl_setopt($charam, CURLOPT_POSTFIELDS, $data);
//ob_start();
$curl_result = curl_exec ($charam);
//curl_close ($charam);
return $curl_result;
//ob_end_clean();
//curl_close ($charam);
//unset($charam);
}
【问题讨论】:
-
Facebook 有一个 API。使用它。
标签: php web-scraping simple-html-dom