I started experimenting with social signals as ranking factors in Search Engines; by social signals I mean the count of mentions a website has on a social network such as Facebook, Twitter, LinkedIn, StumbleUpon, Google+ and so forth. I correlated a lot of metrics using a spreadsheet, which was time consuming so I decided to write a script to do it for me. I am 80% complete with the entire script so I’m not going to publish it all, but rather just a taste of what I’m doing.
The code below, when executed on Apache, will crawl Topsy and return the number of times a chosen website has been mentioned on Twitter. This code needs to be run in conjunction with a form that passes a text field with the domain name, so you may have to code that up quickly or later the code to bypass the domain inclusion.
Here’s the code:
$domain_name = $_POST['domain'];
$domain_name = strtolower(trim($domain_name));
echo "Results for " . $domain_name . ":
";
// build search queries
$topsy_twitter = 'http://topsy.com/s?q='.$domain_name;
// cURL contents of queries
$topsy_twitter_contents = grab_contents($topsy_twitter);
// Find match on Topsy for Twitter
if(preg_match('/Search results 1<\/strong>-10<\/strong> out of (.*?) tweets/sim', $topsy_twitter_contents, $regs)){
$indexed_pages = substr($regs[1], 0, stripos($regs[1], " "));
$indexed_pages = strip_tags(str_replace(",","",$indexed_pages));
echo "Twitter Mentions: " . $indexed_pages;
}else{
echo "Twitter Mentions: 0";
}
function grab_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
As I mentioned, I’ve adapted this to cover an assortment of social networks and am deciding whether I should compile it into an advanced WordPress Social Metrics Plugin.. watch this space.
Recent Comments