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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 347 | HTML | 17년 전 | 2782 | ||
| 346 | HTML | 17년 전 | 3246 | ||
| 345 | HTML | 17년 전 | 4310 | ||
| 344 | HTML | 17년 전 | 3464 | ||
| 343 | HTML | 17년 전 | 3166 | ||
| 342 | HTML | 17년 전 | 3818 | ||
| 341 | HTML | 17년 전 | 3371 | ||
| 340 | HTML | 17년 전 | 2723 | ||
| 339 | HTML | 17년 전 | 3683 | ||
| 338 | HTML | 17년 전 | 6254 | ||
| 337 | HTML | 17년 전 | 4231 | ||
| 336 | HTML | 17년 전 | 2935 | ||
| 335 | HTML |
카프카07
|
17년 전 | 3191 | |
| 334 | HTML |
진정한승리
|
17년 전 | 4856 | |
| 333 | HTML | 17년 전 | 3053 | ||
| 332 | HTML |
|
17년 전 | 3281 | |
| 331 | HTML | 17년 전 | 3831 | ||
| 330 | HTML | 17년 전 | 2856 | ||
| 329 | HTML | 17년 전 | 2635 | ||
| 328 | HTML | 17년 전 | 4823 | ||
| 327 | HTML | 17년 전 | 5611 | ||
| 326 | HTML | 17년 전 | 7309 | ||
| 325 | HTML | 17년 전 | 3611 | ||
| 324 | HTML | 17년 전 | 3811 | ||
| 323 | HTML | 17년 전 | 3581 | ||
| 322 | HTML | 17년 전 | 6088 | ||
| 321 | HTML | 17년 전 | 3271 | ||
| 320 | HTML | 17년 전 | 3831 | ||
| 319 | JavaScript | 17년 전 | 9006 | ||
| 318 | HTML |
|
17년 전 | 3387 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기