开放的编程资料库

当前位置:我爱分享网 > PHP教程 > 正文

雅虎 SEO 域结果抓取器

大约一个月前我发布了我的 PHP Google Grabber 脚本,它大受欢迎,甚至产生了 Python 和 Groovy 版本。通过简单地提供一个域名(或多个,如果你循环函数)来获取在谷歌中索引的页面数量可以节省你很多时间。我每月运行一次这个脚本来跟踪我客户的网站——他们中的许多人使用我们构建的 CMS,因此我可以深入了解他们在 SEO 方面的表现。

虽然雅虎!在搜索部门 Yahoo! 的相关性几乎不如 Google。仍然是互联网上访问量最大的网站。由于我已经构建了代码的基本框架(来自我的 Google Grabber),我认为花一些时间对 Yahoo! 进行处理可能会有所帮助。

代码

/* return result number */
function get_yahoo_results($domain = 'davidwalsh.name')
{
	// get the result content
	$content = file_get_contents('https://siteexplorer.search.yahoo.com/search?p=http%3A%2F%2F'.$domain.'&bwm=p&bwms=p&fr2=seo-rd-se');

	// parse to get results
	$pages = str_replace(array(' ',')','('),'',get_match('/Pages (.*) /isU',$content));
	$inlinks = str_replace(array(' ',')','('),'',get_match('/Inlinks (.*) /isU',$content));

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

	// return result
	return $return;
}

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

用法

domains = array('davidwalsh.name','digg.com','yahoo.com','cnn.com','dzone.com','some-domain-that-doesnt-exist.com');
foreach($domains as $domain)
{
	$result = get_yahoo_results($domain);
	echo $domain,': ',$result['pages'],' pages, ',$result['inlinks'],' inlinks';
}

//davidwalsh.name: 204 pages, 518 inlinks
//digg.com: 20,700,000 pages, 14,300,000 inlinks
//yahoo.com: 1,290,000,000 pages, 4,650,000 inlinks
//cnn.com: 7,510,000 pages, 1,090,000 inlinks
//dzone.com: 776,000 pages, 15,000 inlinks
//some-domain-that-doesnt-exist.com: 0 pages, 0 inlinks

很像我的 Google Grabber,您可能需要调整连接到 Yahoo! 的方法。基于您的托管环境。 cURL 可能是您的最佳选择。

未经允许不得转载:我爱分享网 » 雅虎 SEO 域结果抓取器

感觉很棒!可以赞赏支持我哟~

赞(0) 打赏