xml 추출 후 snoopy로 파싱문의드립니다.
본문
안녕하세요.
RSS 파싱에 대해서 문의드립니다.
http://www.kfiu.org/news/kfiu_news.php
게시판을 우선 feed43 이용해서 XML 추출했습니다.
추출된 결과:
http://feed43.com/0665468503707712.xml
Snoopy 파싱:
http://imkibonojo.or.kr/post_rss.php
다시
Snoopy 이용해서 DB에 업데이트 하려고하는데 어디가 문제인지 문의드립니다.
<?php
define('_INDEX_', true);
include_once('./_common.php');
//ver1.0 150417 @_untitle_d
function insert_write($newpost)
{
global $g5;
//게시판 테이블 정보
$bo_table = $newpost[bo_table];
if(!strlen($bo_table)) return FALSE; //bo_table 값이 지정되지 않았습니다.
$board = sql_fetch(" select * from {$g5['board_table']} where bo_table = '$bo_table' ");
if(!$board) return FALSE; //bo_table이 존재하지 않습니다.
//회원정보 및 권한 확인
$member = get_member($newpost[mb_id]);
if(!$member) return FALSE; //mb_id가 존재하지 않습니다.
//if($board[bo_write_level] > $member[mb_level]) return FALSE; //글쓰기 권한이 없습니다.
//카테고리 설정
$ca_name = $newpost[ca_name];
if ($ca_name && strpos($board[bo_category_list], $ca_name) === FALSE){
$category_list = $board[bo_category_list]."|".$ca_name;
$sql = " update {$g5['board_table']} set bo_category_list = '$category_list' where bo_table = '$bo_table' ";
sql_query($sql);
}
//변수 정리
$write_table = $g5[write_prefix].$bo_table;
$wr_num = get_next_num($write_table);
$ca_name = addslashes($ca_name);
$html = "html1";
$secret = "";
$mail = "";
$wr_subject = addslashes(trim($newpost[wr_subject]));
$wr_content = addslashes(trim($newpost[wr_content]));
if(!$wr_subject) return FALSE; //글 제목이 없습니다.
if(!$wr_content) return FALSE; //글 내용이 없습니다.
$mb_id = $member[mb_id];
$wr_password = $member[mb_password];
$wr_name = $board[bo_use_name] ? $member[mb_name] : $member[mb_nick];
$wr_email = $member[mb_email];
$wr_homepage = $member[mb_homepage];
for($i=1; $i<=10; $i++){
$wr = "wr_{$i}";
${$wr} = addslashes($newpost[$wr]);
}
$wr_link1 = $newpost[wr_link1];
$wr_link2 = $newpost[wr_link2];
//글 입력하기
$sql = " insert into $write_table
set wr_num = '$wr_num',
wr_reply = '',
wr_comment = 0,
ca_name = '$ca_name',
wr_option = '$html,$secret,$mail',
wr_subject = '$wr_subject',
wr_content = '$wr_content',
wr_link1 = '$wr_link1',
wr_link2 = '$wr_link2',
wr_link1_hit = 0,
wr_link2_hit = 0,
wr_hit = 0,
wr_good = 0,
wr_nogood = 0,
mb_id = '$mb_id',
wr_password = '$wr_password',
wr_name = '$wr_name',
wr_email = '$wr_email',
wr_homepage = '$wr_homepage',
wr_datetime = '".G5_TIME_YMDHIS."',
wr_last = '".G5_TIME_YMDHIS."',
wr_ip = '{$_SERVER['REMOTE_ADDR']}',
wr_1 = '$wr_1',
wr_2 = '$wr_2',
wr_3 = '$wr_3',
wr_4 = '$wr_4',
wr_5 = '$wr_5',
wr_6 = '$wr_6',
wr_7 = '$wr_7',
wr_8 = '$wr_8',
wr_9 = '$wr_9',
wr_10 = '$wr_10' ";
//echo $sql;
sql_query($sql);
$wr_id = mysql_insert_id();
sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' "); //부모 아이디에 UPDATE
sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$bo_table}', '{$wr_id}', '{$wr_id}', '".G5_TIME_YMDHIS."', '$mb_id' ) "); //새글 INSERT
sql_query(" update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$bo_table}' "); //게시글 1 증가
//return array('bo_table' => $bo_table, 'wr_id' => $wr_id, 'sca' => $ca_name);
return TRUE;
}
$bo_table = 'rss'; //게시판 테이블
$write_table = $g5[write_prefix].$bo_table;
$url = 'http://feed43.com/0665468503707712.xml'; //RSS (http://www.insidechina.co.kr/Rss/RssNews.asp)
// http://csf.kiep.go.kr/www/user/rss/rssList.jsp?tid=1 중국전문가포럼
require "lib/Snoopy.class.php";
ini_set("allow_url_fopen","1");
$snoopy = new Snoopy;
$snoopy->fetch($url);
echo $snoopy;
$xml = @simplexml_load_string($snoopy->results);
foreach($xml->channel->item as $item) {
$sql = "select count(*) as cnt from $write_table where wr_link1 = '".$item->link."' and wr_is_comment = 0";
$row = sql_fetch($sql);
if ($row['cnt'] == 0){
$newpost = array(
'mb_id' => 'admin',
'bo_table' => $bo_table,
'wr_subject' => $item->title,
'wr_content' => $item->description."...<br><br>... [<a target='_blank' href='".$item->link."'>더보기</a>]",
'wr_link1' => $item->link
);
insert_write($newpost);
}
}
?>
<a href="<?=G5_BBS_URL?>/board.php?bo_table=<?=$bo_table?>">결과보기</a>
!-->
답변을 작성하시기 전에 로그인 해주세요.