本人wordpress版本为3.0.1,非此版本的,可以查看wp-includes/post.php文件中的
wp_insert_post函数进行模仿发布文章,该函数第一个参数即为博客数据数组。
google reader可访问如下地址(红色字体为需要导入的博客链接),建议将xml文件保存至本地。
https://www.google.com/reader/atom/feed/
http://haroldphp.iteye.com/rss?n=44444
在wordpress/wp-admin/目录下新建fetch.php文件(然后运行该文件即可),源代码如下:
<?php
require_once ('./admin.php');
$dom = new DOMDocument ( '1.0' );
//载入保存至本地的xml文件,本人保存至wordpress根目录
$xmlfile = '../haroldphp.xml';
$dom->load ( $xmlfile );
$dom->saveXML ();
//存储xml数据的数组
$dataArray = array ();
$entryArray = $dom->getElementsByTagName ( 'entry' );
foreach ( $entryArray as $entry ) {
//博客标题
$dataArray ['post_title'] = $entry->getElementsByTagName ( 'title' )->item ( 0 )->nodeValue;
//博客发表时间
$published = $entry->getElementsByTagName ( 'published' )->item ( 0 )->nodeValue;
$dataArray ['post_date_gmt'] = $dataArray ['post_date'] = $published;
//博客更新时间
$updated = $entry->getElementsByTagName ( 'updated' )->item ( 0 )->nodeValue;
$dataArray ['post_modified']= $dataArray ['post_modified_gmt'] = $updated;
$summary = $entry->getElementsByTagName ( 'summary' )->item ( 0 )->nodeValue;
//过滤无用数据标签
$replace = '/<span style="color:red">\s*<a.*style="color:red">((已有 <strong>\d+<\/strong> 人发表留言,猛击->><strong>这里<\/strong><<-参与讨论)|(本文的讨论也很精彩,浏览讨论>>))/m';
$replace2 = '/<span style="color:#e28822">ITeye推荐<\/span>/';
$replace3 = '~<ul><li><a\s*href="http://(.)*\.iteye\.com/clicks/(\d)+"><span\s*style="color:red;font-weight:bold">.+ </span></a></li></ul>~m';
$summary = preg_replace ( $replace, '', $summary );
$summary = preg_replace ( $replace2, '', $summary );
$summary = preg_replace ( $replace3, '', $summary );
$dataArray ['post_content'] = $summary;
//默认为立即发布,如果需要为草稿,可改为draft
$dataArray['post_status'] = 'publish';
//使用wp自带发布文章函数将数据写入数据库
$post_ID = wp_insert_post ( $dataArray );
if (is_wp_error ( $post_ID ) || empty ( $post_ID ))
echo $dataArray ['post_title'] . ' --- 导入数据出错';
add_meta ( $post_ID );
add_post_meta ( $post_ID, '_edit_last', $GLOBALS ['current_user']->ID
);
echo $dataArray ['post_title'] . ' added success!!!';
}
分享到:
相关推荐
这是我在iteye网站的技术博客
NULL 博文链接:https://uule.iteye.com/blog/980620
WordPress是一个注重美学、易用性和网络标准的...使用WordPress可以搭建功能强大的网络信息发布平台,但更多的是应用于个性化的博客。针对博客的应用,WordPress能让您省却对后台技术的担心,集中精力做好网站的内容。
iteye博客抓取 网页解析 关键字提取 jsoup解析网页 包含数据库文件
Oracle大数据量导入 博文链接:https://abe.iteye.com/blog/1054515
NULL 博文链接:https://xiaoshenge.iteye.com/blog/1416287
NULL 博文链接:https://itshu.iteye.com/blog/1754672
NULL 博文链接:https://enefry.iteye.com/blog/986651
NULL 博文链接:https://zhengmingwei.iteye.com/blog/857936
oracle-excel导入导出 博文链接:https://fackyou200.iteye.com/blog/796633
NULL 博文链接:https://kingding.iteye.com/blog/2435018
message solution(SSH)_ITeye闫小甲博客
最新的ITeye月刊,覆盖各个It的行业最新信息,了解最新的咨询。
NULL 博文链接:https://huhongyu.iteye.com/blog/1844333
NULL 博文链接:https://duqiangcise.iteye.com/blog/734041
NULL 博文链接:https://zhouxianglh.iteye.com/blog/1125009
wordpress
NULL 博文链接:https://xurichusheng.iteye.com/blog/1863479
NULL 博文链接:https://hahawowo.iteye.com/blog/783874
mybatis+mysql+springmvc + multidatasource+Atomikos 多数据源 (可以跑通的) http://knight-black-bob.iteye.com/blog/2253726