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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 107 | HTML |
홀로남은자
|
19년 전 | 3336 | |
| 106 | HTML | 19년 전 | 3221 | ||
| 105 | HTML |
그레이스웹
|
19년 전 | 4951 | |
| 104 | HTML |
|
19년 전 | 6289 | |
| 103 | HTML |
|
19년 전 | 5268 | |
| 102 | HTML |
|
19년 전 | 4625 | |
| 101 | HTML |
|
19년 전 | 3438 | |
| 100 | HTML |
|
19년 전 | 6193 | |
| 99 | HTML |
|
19년 전 | 5026 | |
| 98 | HTML |
|
19년 전 | 3450 | |
| 97 | HTML |
|
19년 전 | 4441 | |
| 96 | HTML | 19년 전 | 6880 | ||
| 95 | HTML | 19년 전 | 4335 | ||
| 94 | HTML | 19년 전 | 3219 | ||
| 93 | HTML | 19년 전 | 5761 | ||
| 92 | HTML | 19년 전 | 4153 | ||
| 91 | HTML |
|
19년 전 | 5183 | |
| 90 | HTML |
|
19년 전 | 3242 | |
| 89 | HTML |
|
19년 전 | 3164 | |
| 88 | HTML |
|
19년 전 | 3631 | |
| 87 | HTML | 19년 전 | 5167 | ||
| 86 | HTML | 19년 전 | 4812 | ||
| 85 | HTML | 19년 전 | 4141 | ||
| 84 | HTML |
|
19년 전 | 3494 | |
| 83 | HTML |
|
19년 전 | 3154 | |
| 82 | HTML | 19년 전 | 4919 | ||
| 81 | HTML |
|
19년 전 | 4135 | |
| 80 | HTML | 19년 전 | 4459 | ||
| 79 | HTML | 19년 전 | 3585 | ||
| 78 | HTML |
|
19년 전 | 4923 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기