如何抓取facebook用户个人资料页面


How to scrape a facebook user profile page

我想知道如何使用php抓取facebook用户个人资料页面。我尝试使用CURL, fsockopen和file_get_contents,但它没有返回处理过的HTML页面。它只返回充满JS代码的HTML页面。看来,facebook是用Javascript加载页面的。所以,我想知道,如何使用php获得处理过的HTML页面。

注意:1. 从facebook注销。2. 点击用户URL例如:http://www.facbook.com/USERNAME

只需使用facebook graph,那么更容易获得json格式的信息比正则化html

在chrome或其他知道如何处理json的浏览器中打开这个,

http://graph.facebook.com/php

{
   "id": "6358087478",
   "name": "PHP",
   "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/41787_6358087478_3246078_s.jpg",
   "link": "http://www.facebook.com/PHP",
   "category": "Product/service",
   "likes": 117991,
   "website": "www.php.net",
   "username": "PHP",
   "founded": "1994"
}

获取任何特定用户的任何详细信息的更好方法是构建一个facebook应用程序并使用他们提供的API .

认证API可用于获取有关特定用户的所有信息(包括电子邮件,喜欢位置等)

由于隐私条款,facebook肯定会隐藏用户信息。

最好的开始方式是阅读这个…http://developers.facebook.com/docs/

我尝试了搜索引擎用户代理。它起作用了!

$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
$url = "http://www.facebook.com/USERNAME";
$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, 10);
$html = curl_exec($ch);