createrss.php,先在"我的文章分类"和"最新文章列表"中间找到分类的联接(RSS文档),然后找到每一页(每页里面是20片文章),然后在每一页里面找到文章的地址,再找到内容,最后生成RSS
这个文件只能处理这种形式的blog,但是sina是ajax做的,用户的主页形式不一样,要重写createrss.php,以便适应不用的用户
这个文件只能处理这种形式的blog,但是sina是ajax做的,用户的主页形式不一样,要重写createrss.php,以便适应不用的用户
<?php
require_once "rss.genesis.php";
require_once "magpierss/rss_fetch.inc";
//生成Rss
$myrss=new rssGenesis();
//CHANNEL
$myrss->setChannel (
null, // Title
"http://www.ci123.com", // Link
null, // Description
"zh-cn", // Language
null, // Copyright
null, // Managing Editor
null, // WebMaster
null, // Rating
"auto", // PubDate
"auto", // Last Build Date
"Test", // Category
null, // Docs
null, // Time to Live
null, // Skip Days
null // Skip Hours
);
$snoopy = new Snoopy();
$url="http://blog.sina.com.cn/m/xujinglei";
$snoopy->fetch($url);
$string=$snoopy->results;
$begin=strpos($string,"我的文章分类");
$end =strpos($string,"最新文章列表");
$string=substr($string,$begin,$end-$begin);
//echo $string; //现在$string里面包含了所有分类的url
preg_match_all("|(sns).[^']{4,}|i",$string,$out);
//对于每个分类,取出其内容(RSS)
for($i=0;$i<1;$i++)//count($out[0]);$i++)
{
$url="http://blog.sina.com/".$out[0][$i];
$url=str_replace("amp;","",$url);
//$url="http://localhost/234.xml";
$snoopy->fetch($url); //抓取RSS
preg_match_all("|(/sns/).[^<]+|i",$snoopy->results,$matches); //匹配其中的每一页的RSS地址
$page_count=count($matches[0]); //该分类下面有$page_count页,其每一页的地址仍然要过滤掉amp;
//
// $mathches里面的数组结构图
// $matches[$page_count]{
// "0"=> 第二页
// "1"=> 第三页
// "$page_count-2" => 第 $page_count 页
// }
//...这里抓取第一个页面($url)的RSS..........//
$pagerss=fetch_rss($url);
//$pagerss->items里面包含了所有文章的内容(标题,修改日期,链接)
//下面的这段分析出RSS的内容
foreach($pagerss->items as $line)
{
//echo $line["title"];
//echo "<br>".$line["link"];
//echo "<br>".$line["sns"]["pubdate"];
//echo "<br><hr>";
$htmlpage_url=$line["link"];
$htmlpage_url="http://blog.sina.com.cn".$page_url;
$snoopy->fetch($htmlpage_url);
ereg("<DIV>.*</DIV>",$snoopy->results,$description);
$myrss->addItem (
$line["title"], // Title
"http://blog.sina.com.cn".$line["link"], // Link
$description[0], // Description
$line["sns"]["pubdate"], //Publication Date
"Test" // Category
);
//然后要找到每个页面,抓取页面的html,找到其中的内容,存入description里面
}
//下面抓取第2页到第$page_count页($matches["0"][$page]) 仍然要过滤掉amp;
for($page=0;$page<$page_count - 1;$page++) //针对该分类的每一页,直接用RSS得到文章的标题,更新时间和链接地址
{
$url=$matches["0"]["$page"];
$url=str_replace("amp;","",$url);
$url="http://blog.sina.com".$url;
$pagerss=fetch_rss($url);
//找到该页所有的文章信息
foreach($pagerss->items as $line)
{
;//对每个页面进行抓取
$htmlpage_url=$line["link"];
$htmlpage_url="http://blog.sina.com.cn".$htmlpage_url;
$snoopy->fetch($htmlpage_url);
ereg("<DIV>.*</DIV>",$snoopy->results,$description);
$myrss->addItem (
$line["title"], // Title
"http://blog.sina.com.cn".$line["link"], // Link
$description[0], // Description
$line["sns"]["pubdate"], //Publication Date
"Test" // Category
);
}
//抓取RSS的代码
}
}
$myrss->setInput (
null, // Title
null, // Description
null, // Name
null // Link
);
// FINISH
$myrss->createFile ("rss.xml");
?>
require_once "rss.genesis.php";
require_once "magpierss/rss_fetch.inc";
//生成Rss
$myrss=new rssGenesis();
//CHANNEL
$myrss->setChannel (
null, // Title
"http://www.ci123.com", // Link
null, // Description
"zh-cn", // Language
null, // Copyright
null, // Managing Editor
null, // WebMaster
null, // Rating
"auto", // PubDate
"auto", // Last Build Date
"Test", // Category
null, // Docs
null, // Time to Live
null, // Skip Days
null // Skip Hours
);
$snoopy = new Snoopy();
$url="http://blog.sina.com.cn/m/xujinglei";
$snoopy->fetch($url);
$string=$snoopy->results;
$begin=strpos($string,"我的文章分类");
$end =strpos($string,"最新文章列表");
$string=substr($string,$begin,$end-$begin);
//echo $string; //现在$string里面包含了所有分类的url
preg_match_all("|(sns).[^']{4,}|i",$string,$out);
//对于每个分类,取出其内容(RSS)
for($i=0;$i<1;$i++)//count($out[0]);$i++)
{
$url="http://blog.sina.com/".$out[0][$i];
$url=str_replace("amp;","",$url);
//$url="http://localhost/234.xml";
$snoopy->fetch($url); //抓取RSS
preg_match_all("|(/sns/).[^<]+|i",$snoopy->results,$matches); //匹配其中的每一页的RSS地址
$page_count=count($matches[0]); //该分类下面有$page_count页,其每一页的地址仍然要过滤掉amp;
//
// $mathches里面的数组结构图
// $matches[$page_count]{
// "0"=> 第二页
// "1"=> 第三页
// "$page_count-2" => 第 $page_count 页
// }
//...这里抓取第一个页面($url)的RSS..........//
$pagerss=fetch_rss($url);
//$pagerss->items里面包含了所有文章的内容(标题,修改日期,链接)
//下面的这段分析出RSS的内容
foreach($pagerss->items as $line)
{
//echo $line["title"];
//echo "<br>".$line["link"];
//echo "<br>".$line["sns"]["pubdate"];
//echo "<br><hr>";
$htmlpage_url=$line["link"];
$htmlpage_url="http://blog.sina.com.cn".$page_url;
$snoopy->fetch($htmlpage_url);
ereg("<DIV>.*</DIV>",$snoopy->results,$description);
$myrss->addItem (
$line["title"], // Title
"http://blog.sina.com.cn".$line["link"], // Link
$description[0], // Description
$line["sns"]["pubdate"], //Publication Date
"Test" // Category
);
//然后要找到每个页面,抓取页面的html,找到其中的内容,存入description里面
}
//下面抓取第2页到第$page_count页($matches["0"][$page]) 仍然要过滤掉amp;
for($page=0;$page<$page_count - 1;$page++) //针对该分类的每一页,直接用RSS得到文章的标题,更新时间和链接地址
{
$url=$matches["0"]["$page"];
$url=str_replace("amp;","",$url);
$url="http://blog.sina.com".$url;
$pagerss=fetch_rss($url);
//找到该页所有的文章信息
foreach($pagerss->items as $line)
{
;//对每个页面进行抓取
$htmlpage_url=$line["link"];
$htmlpage_url="http://blog.sina.com.cn".$htmlpage_url;
$snoopy->fetch($htmlpage_url);
ereg("<DIV>.*</DIV>",$snoopy->results,$description);
$myrss->addItem (
$line["title"], // Title
"http://blog.sina.com.cn".$line["link"], // Link
$description[0], // Description
$line["sns"]["pubdate"], //Publication Date
"Test" // Category
);
}
//抓取RSS的代码
}
}
$myrss->setInput (
null, // Title
null, // Description
null, // Name
null // Link
);
// FINISH
$myrss->createFile ("rss.xml");
?>