快速实现DEDECMS织梦系统伪标题采集

原理很简单,在后台采集时候,自动替换标题关键词,我想你懂的。

好吧,不多说,开工了:

1.把库表准备,sql脚本弄一下,表名cz_str_replace

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for cz_str_replace
-- ----------------------------
DROP TABLE IF EXISTS `cz_str_replace`;
CREATE TABLE `cz_str_replace` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `interconvert` int(1) unsigned zerofill DEFAULT '0',
  `find` varchar(20) CHARACTER SET gbk DEFAULT NULL,
  `replace` varchar(20) CHARACTER SET gbk DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `cz_str_replace` VALUES ('1', '0', '肌肉', '鸡肉');
INSERT INTO `cz_str_replace` VALUES ('2', '0', '怎么', '如何');
INSERT INTO `cz_str_replace` VALUES ('3', '0', '为何', '为什么');
INSERT INTO `cz_str_replace` VALUES ('4', '0', '为什么', '为何');
INSERT INTO `cz_str_replace` VALUES ('5', '0', '几种', '那些');
INSERT INTO `cz_str_replace` VALUES ('6', '0', '正解', '详解');

PS:interconvert 用法:0 是默认值,为替换;1为置换(对换位置)

2.准备对采集php程序动刀了,打开include/dedecollection.class.php

首先在类里加上先加一个替换的方法

//采集内容伪原创替换
    function pr_str_replace($str)
    {
     $dsql = new DedeSql(false);
     $dsql->SetQuery("SELECT * FROM `cz_str_replace`");
     $dsql->Execute();
     while ($row = $dsql->GetArray())
     {
       if($row['interconvert'] == 1)
       {
        $str = str_replace($row['find'], "@@@@", $str);
        $str = str_replace($row['replace'], $row['find'], $str);
        $str = str_replace("@@@@", $row['replace'], $str);
       }
       else if($row['interconvert'] == 0)
       {
          $str = str_replace($row['find'], $row['replace'], $str);
       }
     }
     return $str;
    }

接下来,把采集入库前需要替换的内容加上这个方法

//伪原创标题替换
    $v['title'] = $this->pr_str_replace($v['title']);

    $inquery = "INSERT INTO `#@__co_htmls` (`nid` ,`typeid`, `title` , `litpic` , `url` , `dtime` , `isdown` , `isexport` , `result`)
              VALUES ('{$this->noteId}' , '0', '".addslashes($v['title'])."' , '".addslashes($v['image'])."' , '".addslashes($v['link'])."' , 'dtime' , '0' , '0' , ''); ";
    $this->dsql->ExecuteNoneQuery($inquery);

3.大功告成,猛击采集按钮一分钟……

好了,入门的童鞋都动手试试吧

  

posted on 2013-01-10 14:27  seekguo  阅读(120)  评论(0)    收藏  举报

导航