如果大家稍加仔细看一下就能发现一个问题,我们下面几个抓取百度收录或快照或热词的程序中都有一个函数file_get_contents(),他是php采集网页常用的哦。
代码如下
复制代码
<?
/*
抓取百度收录代码
*/
function baidu($s){
$baidu="http://www.baidu.com/s?wd=site%3A".$s;
$site=file_get_contents($baidu);
//$site=iconv("gb2312", "UTF-8", $site);
ereg("找到相关网页(.*)篇,", $site,$count);
$count=str_replace("找到相关网页","",$count);
$count=str_replace("篇,","",$count);
$count=str_replace("约","",$count);
$count=str_replace(",","",$count);
return $count[0];
}
echo baidu(www.3ppt.com); //获取好主题在百度中的收录数量
?>
获取百度的热词
<?php
/**
* * @user 小杰
* @return array 返回百度的热词数据(数组返回)
*/
function getBaiduHotKeyWord()
{
$templateRss = file_get_contents('http://top.baidu.com/rss_xml.php?p=top10');
If (preg_match('/<table>(.*)</table>/is', $templateRss, $_description)) {
$templateRss = $_description [0];
$templateRss = str_replace("&", "&", $templateRss);
}
$templateRss = "<?xml version="1.0" encoding="GBK"?>" . $templateRss;
$xml = simplexml_load_String($templateRss);
foreach ($xml->tbody->tr as $temp) {
if (!empty ($temp->td->a)) {
$keyArray [] = trim(($temp->td->a));
return $keyArray;
print_r(getBaiduHotKeyWord());
这是在网上找的 稍微修改了下 将下面代码写入php文件
百度收录和百度快照时间