PHP+Snoopy 파싱 질문 드립니다.
안녕하세요?
제가 현재 활동하는 네이버 카페가 RSS 제공을 하지 않아서
게시판을 파싱하여 데이터를 뽑아오려고 하는데, 네이버 카페가 막아둔건지
소스에 문제가 있는지 전혀 모르겠습니다...ㅠㅠ
include './Snoopy.class.php';
$s = new snoopy;
$s->referer = 'cafe.naver.com';
$s->fetch("http://cafe.naver.com/sakurahubuki.cafe?iframe_url=/ArticleList.nhn%3Fsearch.clubid=16192748%26search.menuid=26%26search.boardtype=L");
$t = explode("<td class=\"view-count m-tcol-c b last-child\"></td>", $s->results);
$r = explode("<div class=\"list-btn\">", $t[0]);
echo $r[1];
정규식을 써서, 게시글들을 뽑아오려고 해도 않되고 이리저리 방법을 갈구 해봤지만 제 실력으론 무리인것 같습니다...
소스에 문제가 있는건가요? 도움부탁드리겠습니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
제가 현재 활동하는 네이버 카페가 RSS 제공을 하지 않아서
게시판을 파싱하여 데이터를 뽑아오려고 하는데, 네이버 카페가 막아둔건지
소스에 문제가 있는지 전혀 모르겠습니다...ㅠㅠ
include './Snoopy.class.php';
$s = new snoopy;
$s->referer = 'cafe.naver.com';
$s->fetch("http://cafe.naver.com/sakurahubuki.cafe?iframe_url=/ArticleList.nhn%3Fsearch.clubid=16192748%26search.menuid=26%26search.boardtype=L");
$t = explode("<td class=\"view-count m-tcol-c b last-child\"></td>", $s->results);
$r = explode("<div class=\"list-btn\">", $t[0]);
echo $r[1];
정규식을 써서, 게시글들을 뽑아오려고 해도 않되고 이리저리 방법을 갈구 해봤지만 제 실력으론 무리인것 같습니다...
소스에 문제가 있는건가요? 도움부탁드리겠습니다.<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
댓글 1개
14년 전
음냐.... 저는 그냥 만들어서 썼는데요......
중고나라 예제입니다. 도움이 되시길 바랍니다.
function getGB($server, $jsp, $url) {
$map_query = str_replace(" ","%20",$url);
$pquery = $jsp;
$fp = fsockopen ($server, 80, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)";
} else {
fputs($fp, "GET {$pquery}?");
fputs($fp, $url);
fputs($fp, " HTTP/1.1\r\n");
fputs($fp, "Host: {$server}\r\n");
fputs($fp, "Connection: Close\r\n\r\n");
$header = "";
while (!feof($fp)) {
$out = fgets ($fp,512);
if (trim($out) == "") {
break;
}
$header .= $out;
}
$mapbody = "";
while (!feof($fp)) {
$out = fgets ($fp,512);
$mapbody .= $out;
}
fclose ($fp);
}
return $mapbody;
}
<li id="title">naver : 중고나라</li>
<?
$tmp=getGB("cafe.naver.com","/ArticleList.nhn","search.boardtype=L&search.menuid=334&search.questionTab=A&search.clubid=10050146&search.totalCount=151&search.page=1");
//echo nl2br(htmlspecialchars($tmp));<br />
//echo $tmp;
$tmp=explode("<div class=\"article-board m-tcol-c\">",$tmp);
$item=explode("<span class=\"aaa\">",$tmp[1]);
for ($i=1;$i<count($item) && $i<5;$i++) {
$tmp=explode("<input",$item[$i]);
$ttt=explode("class=\"m-tcol-c\">",$tmp[0]);
$ttt[0]=str_replace("<a href='/ArticleRead.nhn","<a target='_blank' href=\"http://cafe.naver.com/ArticleRead.nhn",$ttt[0]);
$title[$i]=$ttt[0]."class=\"m-tcol-c\">".strip_tags($ttt[1])."</a>";
//$title[$i]=str_replace("<a href='/ArticleRead.nhn","<a target='_blank' href=\"http://cafe.naver.com/ArticleRead.nhn",$tmp[0]);
}
for ($i=1;$i<count($item) && $i<5;$i++) {
?>
<li>
<nobr style='display:block; overflow:hidden; width:450px;'><?=$title[$i]?></nobr>
</li>
<?
}
?>
<br />
중고나라 예제입니다. 도움이 되시길 바랍니다.
function getGB($server, $jsp, $url) {
$map_query = str_replace(" ","%20",$url);
$pquery = $jsp;
$fp = fsockopen ($server, 80, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)";
} else {
fputs($fp, "GET {$pquery}?");
fputs($fp, $url);
fputs($fp, " HTTP/1.1\r\n");
fputs($fp, "Host: {$server}\r\n");
fputs($fp, "Connection: Close\r\n\r\n");
$header = "";
while (!feof($fp)) {
$out = fgets ($fp,512);
if (trim($out) == "") {
break;
}
$header .= $out;
}
$mapbody = "";
while (!feof($fp)) {
$out = fgets ($fp,512);
$mapbody .= $out;
}
fclose ($fp);
}
return $mapbody;
}
<li id="title">naver : 중고나라</li>
<?
$tmp=getGB("cafe.naver.com","/ArticleList.nhn","search.boardtype=L&search.menuid=334&search.questionTab=A&search.clubid=10050146&search.totalCount=151&search.page=1");
//echo nl2br(htmlspecialchars($tmp));<br />
//echo $tmp;
$tmp=explode("<div class=\"article-board m-tcol-c\">",$tmp);
$item=explode("<span class=\"aaa\">",$tmp[1]);
for ($i=1;$i<count($item) && $i<5;$i++) {
$tmp=explode("<input",$item[$i]);
$ttt=explode("class=\"m-tcol-c\">",$tmp[0]);
$ttt[0]=str_replace("<a href='/ArticleRead.nhn","<a target='_blank' href=\"http://cafe.naver.com/ArticleRead.nhn",$ttt[0]);
$title[$i]=$ttt[0]."class=\"m-tcol-c\">".strip_tags($ttt[1])."</a>";
//$title[$i]=str_replace("<a href='/ArticleRead.nhn","<a target='_blank' href=\"http://cafe.naver.com/ArticleRead.nhn",$tmp[0]);
}
for ($i=1;$i<count($item) && $i<5;$i++) {
?>
<li>
<nobr style='display:block; overflow:hidden; width:450px;'><?=$title[$i]?></nobr>
</li>
<?
}
?>
<br />
게시판 목록
퍼블리셔팁
퍼블리싱과 관련된 유용한 정보를 공유하세요.
질문은 상단의 QA에서 해주시기 바랍니다.
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 377 | HTML | 15년 전 | 5023 | ||
| 376 | HTML | 15년 전 | 3122 | ||
| 375 | HTML | 16년 전 | 3558 | ||
| 374 | HTML | 16년 전 | 3495 | ||
| 373 | HTML | 16년 전 | 3596 | ||
| 372 | HTML |
|
16년 전 | 3311 | |
| 371 | HTML | 16년 전 | 4119 | ||
| 370 | HTML | 16년 전 | 3307 | ||
| 369 | HTML | 16년 전 | 3292 | ||
| 368 | HTML | 16년 전 | 3552 | ||
| 367 | HTML | 16년 전 | 4030 | ||
| 366 | HTML |
잠자리똥꾸멍
|
16년 전 | 3028 | |
| 365 | HTML | 16년 전 | 3689 | ||
| 364 | HTML | 16년 전 | 4620 | ||
| 363 | HTML | 16년 전 | 3206 | ||
| 362 | HTML | 16년 전 | 2976 | ||
| 361 | HTML | 16년 전 | 2467 | ||
| 360 | HTML |
|
16년 전 | 3202 | |
| 359 | HTML | 16년 전 | 5666 | ||
| 358 | HTML | 16년 전 | 3199 | ||
| 357 | HTML | 17년 전 | 6307 | ||
| 356 | HTML | 17년 전 | 6169 | ||
| 355 | HTML | 17년 전 | 4175 | ||
| 354 | HTML | 17년 전 | 3472 | ||
| 353 | HTML | 17년 전 | 2619 | ||
| 352 | HTML | 17년 전 | 3713 | ||
| 351 | HTML | 17년 전 | 3143 | ||
| 350 | HTML | 17년 전 | 5560 | ||
| 349 | HTML | 17년 전 | 4662 | ||
| 348 | HTML | 17년 전 | 3854 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기