How to scrape a facebook user profile page
I like to know how to scrape a facebook user profile page using php. I tried using CURL, fsockopen and file_get_contents but it is not returning the processed HTML page. It just return only the HTML page filled with JS code. It seem开发者_Go百科s that, the facebook loading the page using the Javascript. So, I want to know, how to get the processed HTML page using php.
NOTE: 1. logout from facebook. 2. Hit a user URL eg: http://www.facbook.com/USERNAME
just use facebook graph, so much easier to get the info in json format than regexing html
open this in chrome or some decent browser that knows what to do with 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"
}
Better way to get any details of any particular user is to build a facebook application and use the API provided by them..
The authentication API can be used to get all information(including email, likes location etc.,) about a specific user
And facebook will surely hide user information due to privacy terms..
The best to way to start is to read on this .. http://developers.facebook.com/docs/
I tried with search engine user agent. It works folks!
$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);
精彩评论