PHP查询百度和Google收录情况
开发了一个小型工具用于追踪百度与Google对网站的收录数据,目前该功能已可运行。其核心逻辑并不复杂,主要是利用远程请求获取页面内容,随后进行文本分析处理。
此外,查询Google PR值的过程同样只需访问一个特定地址,因此整体实现难度较低。以下是完整的代码实现,主要流程包括使用file函数获取文件内容、解析数据以及最终输出结果: 复制代码 代码如下:
function baidudetail($domain) {
$baidu_site = 'http://www.baidu.com/baidu?word=site%3A' . $domain;
$baidu_link = 'http://www.baidu.com/baidu?word=link%3A' . $domain;
$baidu_domain = 'http://www.baidu.com/baidu?word=domain%3A' . $domain;
getdetail($baidu_site, 'baidu_site', '相关网页', '篇,用时');
getdetail($baidu_link, 'baidu_link', '相关网页', '篇,用时');
getdetail($baidu_domain, 'baidu_domain', '相关网页', '篇,用时');
}
function googledetail($domain) {
$google_site = 'http://www.google.cn/search?hl=zh-CN&q=site%3A' . $domain;
$google_link = 'http://www.google.cn/search?hl=zh-CN&q=link%3A' . $domain;
getdetail($google_site, 'google_site', ' 个结果,', ' 个。 (搜索用时');
getdetail($google_link, 'google_link', '约有 ', ' 项链接到 '); //102
}
function getdetail($url, $type, $wordf, $wordb) {
$pagecontent = @file($url);
$pagecontent = implode ('', $pagecontent);
$pagecontent = substr(strstr($pagecontent, $wordf), strlen($wordf));
$pagecontent = substr_replace($pagecontent, '', strpos($pagecontent, $wordb));
returndetail($pagecontent, $type);
}
function returndetail($content, $type) {
global $seodetail;
$seodetail[$type] = empty($content) ? 0 : $content;
}
?>