Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MSN Live Search Result Grabber

DZone's Guide to

MSN Live Search Result Grabber

· Web Dev Zone
Free Resource

Tips, tricks and tools for creating your own data-driven app, brought to you in partnership with Qlik.

Within the last month, I've created two popular SEO tools: Google Grabber and Yahoo Grabber. Each grabber goes to the respective website and retrieves the number of pages a specified domain has indexed in the search engine. Having the indexed number of pages so quickly and easily is invaluable and a great sales tool.

Though MSN Live Search isn't a powerhouse search engine / portal, I thought I'd throw in the effort to put one together for Microsoft's search engine.

The PHP Code

/* return result number */
function get_msn_results($domain = 'davidwalsh.name')
{
// get the result content
$content = file_get_contents('http://search.msn.com/results.aspx?q=site%3A'.$domain);

// parse to get results
$pages = get_match('/id="count">(.*)<\/span>/isU',$content);

//explode, get rid of "of"
$pages = explode('of ',$pages);

$return['pages'] = $pages[1] ? $pages[1] : 0;

// return result
return $return;
}

/* helper: does the regex */
function get_match($regex,$content)
{
preg_match($regex,$content,$matches);
return $matches[1];
}

The Usage

$domains = array('davidwalsh.name','digg.com','msn.com','cnn.com','dzone.com','some-domain-that-doesnt-exist.com');
foreach($domains as $domain)
{
$result = get_msn_results($domain);
echo $domain,': ',$result['pages'],'<br />';
}

//davidwalsh.name: 431
//digg.com: 9,610,000
//msn.com: 28,100,000
//cnn.com: 17,100,000
//dzone.com: 138,000
//some-domain-that-doesnt-exist.com: 0

Explore data-driven apps with less coding and query writing, brought to you in partnership with Qlik.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}