首页文章相册图片搜索RSS 2.0

drupal采集

发表于 2008-08-18-16:32:27 编辑

国内的cms程序基本上都内置了采集功能,国外的几乎没有。看到不少使用drupal的朋友都问到采集,在drupal中采集文章其实也很简单。
怎么采集就不说了,小蜜蜂、火车头,专业的采集程序很多,说说在drupal中怎么采集入库。入库一般两种方式:直接导入数据库,web模拟提交。数据库直导,比较危险,副作用大,不过速度快。模拟提交,稳定安全,速度慢。
采取web模拟提交需要使用到drupal的node_save函数,这个函数是用来保存节点的,它会自动加载所有模块定义的nodeapi来完成一个节点的保存工作。下面创建一个模块,来实现数据的导入:
第一步,在sites/all/modules下面创建一个文件夹:test。
第二步,定义一个模块,创建一个文件,文件名:test.info,文件内容:

Quote:
name = "test"
version = "6.x-1.x"
core = "6.x"

第三步,创建模块主文件,test.module,内容:
<?php
function test_menu() {
   
$items = array();

   
$items['test/set'] = array(
       
'title' => 'Photos upload',
       
'page callback' => 'test_set',
       
'access arguments' => array('administer nodes'),
       
'type' => MENU_NORMAL_ITEM,
    );
    return
$items;
}

function
test_set() {
   
$node = array();
   
$node['type'] = 'story';//导入的类型
   
$node['title'] = 'test';//节点标题
   
$node['name'] = 'admin';//节点作者
   
$node['body'] = '111111111111111111111111111111111111';//节点正文
//节点的其它更多内容,分类、评论选项、发表选项、发表时间等,都可以自由定义。
   
   
$node = (object)$node;
   
$node = node_submit($node);//提交数组的数据给node_save。
   
if(node_save($node)){
        echo
'ok';
    }
}
?>

然后启用test模块。启用之后请访问 test/set,看看是不是增加了一个节点。方法就是这样,很简单。可以用火车头采集数据,提交到test/set这个地址来做入库处理。

老大强,搞采集还自己写模块,不过还是要配合火车头,感觉没什

老大强,搞采集还自己写模块,不过还是要配合火车头,感觉没什么优势。
我的是直接用火车头web模拟发布的,速度也很快啊。

请问你的电子邮件地址

想在开发drupal上认识你这个网友,我也在四川。请问你的qq号和电邮。
我的qq:604887011
e-mail: obtrusi@gmail.com

你可以加这个drupal讨论群,群号:5816016 我的

你可以加这个drupal讨论群,群号:5816016
我的邮箱是:yd2004#gmail.com

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <span> <h1> <h2> <h3> <h4>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

同步内容