新浪博客、百度博客搬家(PHP代码)

/*** $Id blogmove.php** 博客搬家** @author skillCoding $date 2011-09-14*/include  'Snoopy.class.php';
include  'function_crawling.php';class BlogMove{var $snoopy;var $links = array();var $blog_links = array();     var $blogs = array();          var $needle_rule = array();        //匹配规则function BlogMove(){$this->snoopy = new Snoopy();}/***  新浪博客搬家* * @param String $url*/function move_sina($url){if(!preg_match('/^http:\/\/blog\.sina\.com\.cn\/\w+/', $url)){return 'Invalid blog address';}$this->snoopy->fetch($url);$str = $this->snoopy->results;$this->snoopy->results = null;$str = html_format($str);//匹配博客目录if(preg_match_all('/http:\/\/blog\.sina\.com\.cn\/s\/articlelist_\d+_0_1\.html/', $str, $m)){$url = $m[0][0];$this->needle_rule = array('page'=>array('s\/articlelist_\d+_0_\d+','\.html$'),'blog'=>array('\/s\/blog_','\.html$'));$this->get_blog_list($url);if($this->blog_links){foreach ($this->blog_links as $link){$this->snoopy->fetch($link);$str = $this->snoopy->results;$this->snoopy->results = null;$str = html_format($str);//匹配标题$titlearr=crawl_match($str, '/<\>/');$title = strip_tags($titlearr[0][0]);//匹配日期$datearr=crawl_match($str, '/(.*?)<\>/');$date = strip_tags($datearr[0][0]);$date = str_replace(array('(',')'), '', $date);//匹配正文$needle = 'id="sina_keyword_ad_area2"';$contentarr=crawl_match($str, '/<\>/',$needle);$content = $contentarr[0];$content = trim(str_replace(array($needle,'class="articalcontent  ">'), '', $content));$blog = array('title'=>$title,'dateline'=>$date,'link'=>$link,'content'=>$content,);array_push($this->blogs, $blog);}return $this->blogs;}else{return 'No Blog';}}else{return 'Invalid blog address';}}/***  百度博客搬家* * @param String $url*/function move_baidu($url){if(!preg_match('/^http:\/\/hi\.baidu\.com\/(.*?)\/blog$/', $url)){return 'Invalid blog address';}$url .= '/index/0';$this->needle_rule = array('page'=>array('\/blog\/index\/','\d+$'),'blog'=>array('\/blog\/item\/','\.html$'));$this->get_blog_list($url);if($this->blog_links){foreach ($this->blog_links as $link){$this->snoopy->fetch($link);$str = $this->snoopy->results;$this->snoopy->results = null;$str = html_format($str);//匹配标题$titlearr=crawl_match($str, '/
(.*?)<\>/');$title = $titlearr[1][1];//匹配日期$datearr=crawl_match($str, '/

(.*?)<\>/'); $date = $datearr[1][0]; //匹配正文 $needle = array('id="blog_text"','class="cnt"'); $contentarr=crawl_match($str, '/ <\>/',$needle); $content = $contentarr[0]; $content = trim(str_replace($needle, '', $content)); $content = ltrim($content,'>'); $blog = array( 'title'=>$title, 'dateline'=>$date, 'link'=>$link, 'content'=>$content, ); array_push($this->blogs, $blog); } return $this->blogs; }else{ return 'No Blog'; } } /** * 获取博文列表 * * @param String $url */ function get_blog_list($url){ $page_links = array(); $this->snoopy->fetchlinks($url); $links = $this->snoopy->results; $this->snoopy->results = null; $page_links = links_filter($links, $this->needle_rule['page']); //获取列表页数 if(!$page_links) array_push($page_links, $url); foreach ($page_links as $page){ $this->snoopy->fetchlinks($page); $links = $this->snoopy->results; $this->snoopy->results = null; $blog_linkarr = links_filter($links, $this->needle_rule['blog']);//获取当前页博文列表 $this->blog_links = array_merge($this->blog_links,$blog_linkarr); } } } <\>
<\><\>

新浪博客、百度博客搬家(PHP代码)

$blog = new BlogMove();
$return = $blog->move_baidu("http://hi.baidu.com/blog/blog/");
$return = $blog->move_sina("http://blog.sina.com.cn/sunsan");

新浪博客、百度博客搬家(PHP代码)

新浪博客、百度博客搬家(PHP代码)相关推荐

  1. php微博图床,php上传图片到新浪图床 | 小灰灰博客

    /** * Created by PhpStorm. * User: 小灰灰 * Date: 2018/12/23 9:02 * Other: 需登录授权api */ class Test { pub ...

  2. 定向爬取新浪股票和百度股票数据

    代码: import reimport requests from bs4 import BeautifulSoupdef getHTMLtext(url,code = "utf-8&quo ...

  3. 获取新浪可转债t+0列表,附上python代码

    ​​​​​​​ @classmethod def get_page_convertibleBonds(cls, pageIndex, retry_count=10):url = "http: ...

  4. 模仿新浪手机频道焦点广告图片切换的代码

    下面的代码,将var pics注释掉的部分去掉,然后到http://auto.qq.com/flash/playswf.swf 去将flashplayer存下来,将下面的代码放到一个html文件中,和 ...

  5. java 新浪短链接_短网址链接生成器代码示例——新浪短链接api接口php、java、Python调用演示...

    短网址api对接成了大家经常遇到的难题,今天以t.cn短链接api接口为例给出三种语言的调用示例代码: 1.APIKEY获取: 2.调用代码 PHP调用代码 $url = 'http://www.ba ...

  6. Windows Live Writer 新浪、网易、blogcn、blogbus、cnblogs博客的设置

    目前国内的一些博客对Windows Live Writer 还不友好.经过测试,新浪和网易的博客已经完美支持Windows Live Writer ,只需要提交博客完整的URL.用户名跟密码,Wind ...

  7. 博客群发软件--用 Windows Live Writer完美发布新浪、网易、blogcn、blogbus、cnbl

    前言: 当今网络博客.微薄铺天盖地,相信即使一个普通的用户也都注册了很多家品牌的博客或者微薄等,那么困扰着大家一个很大的问题,同时在多家博客发布同样的内容,如果说只是简单的文字还好说,复制粘贴就完事了 ...

  8. 新浪云、腾讯云、阿里云、百度云、谷歌云、亚马逊云的区别是什么,哪个更适合国内创业者使用?

    针对题主这个问题 功能 云计算(英语:Cloud Computing),是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需求提供给计算机和其他设备. (引自wikipedia) ...

  9. 百度和它的对手们(2)新浪篇

    这一篇原本是打算作为第三篇的,但由于新浪和五大唱片公司合作的数字音乐营销平台--新浪乐库已经发布,所以提前到第二篇. 前些日子在一个饭局上,陈彤问饭馆的服务员,平时上哪些网站,三个服务员都提到了百度, ...

  10. html仿百度贴吧,模仿百度贴吧?新浪开始内测新浪微吧

    [PConline 资讯]6月28日消息,新浪最近新品不断,此前刚刚推出"新浪微博会员",近日又再度上线了一款类似百度贴吧的产品,为名"微吧".目前,新浪微吧正 ...

最新文章

  1. linux 由一个文件夹复制到另外一个文件夹
  2. NLP专题论文解读:从Chatbot、NER到QA系统...
  3. 解析|一文读懂AGV的关键技术——激光SLAM与视觉SLAM的区别
  4. python详细安装教程linux-Linux系统如何安装Python?新手教程
  5. MFC 多文档中同时打开多个文档
  6. 如何在Web页面上直接打开、编辑、创建Office文档 (转载)
  7. hdu 1022 Train Problem I 解题报告
  8. tensorflow 标准数据读取 tfrecords
  9. CentOS7 上安装 Zookeeper-3.4.9 服务
  10. 两个向量之间的夹角公式_向量的内积
  11. 埃拉托斯特尼筛法 快速查找素数
  12. LeetCode 6038. 向表达式添加括号后的最小结果
  13. 08-spring学习-annotation配置
  14. 保护你的眼睛,把电脑屏幕由白色改为淡绿
  15. 使用Websocket框架之GatewayWorker开发电商平台买家与卖家实时通讯
  16. Web SQL Database
  17. 二阶系统响应指标图_自动控制理论_3.3 二阶系统的瞬态响应
  18. 程序员工具箱--我常用的工具
  19. 爬虫攻守道 - 2023最新 - Python Selenium 实现 - 数据去伪存真,正则表达式谁与争锋 - 爬取某天气网站历史数据
  20. 【Codeforces 1118D1】Coffee and Coursework (Easy version)

热门文章

  1. 程序员的浪漫——欲寄彩笺兼尺素,山长水阔知何处
  2. Golang地图的一些见解
  3. Java控制流程练习“黄金分割点”:寻找某两个整数相除,其结果离黄金分割点0.618最近 ,分母和分子不能同时为偶数,分母和分子 取值范围在[1-20]
  4. 卸载重装Bluestacks安卓模拟器
  5. 重磅推出!安全扫码专业委员会数智商盟码上线了!!
  6. Java多线程通信Suspend和Resume,为什么被弃用,如何导致死锁
  7. 7计数 contact form_接近/门磁开关/计数器-GPS-2314L/R-XXX-LLL
  8. A Physics-Data-Driven Bayesian Method for Heat Conduction Problems
  9. 合字研究——看看藏文里面一共有多少个字吧
  10. 复制浏览器控制台数据的小技巧