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에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 317 | HTML | 17년 전 | 3081 | ||
| 316 | HTML |
갈색야생마
|
17년 전 | 6948 | |
| 315 | HTML |
갈색야생마
|
17년 전 | 4667 | |
| 314 | HTML |
갈색야생마
|
17년 전 | 3765 | |
| 313 | HTML |
갈색야생마
|
17년 전 | 4342 | |
| 312 | HTML |
갈색야생마
|
17년 전 | 2728 | |
| 311 | HTML |
갈색야생마
|
17년 전 | 2308 | |
| 310 | HTML |
갈색야생마
|
17년 전 | 2443 | |
| 309 | HTML |
갈색야생마
|
17년 전 | 2630 | |
| 308 | HTML |
갈색야생마
|
17년 전 | 2872 | |
| 307 | HTML |
갈색야생마
|
17년 전 | 2604 | |
| 306 | HTML | 17년 전 | 4200 | ||
| 305 | HTML |
갈색야생마
|
17년 전 | 3005 | |
| 304 | HTML |
갈색야생마
|
17년 전 | 4145 | |
| 303 | HTML |
갈색야생마
|
17년 전 | 3205 | |
| 302 | HTML |
갈색야생마
|
17년 전 | 2867 | |
| 301 | HTML | 17년 전 | 3815 | ||
| 300 | HTML | 17년 전 | 4020 | ||
| 299 | HTML | 17년 전 | 3068 | ||
| 298 | HTML | 17년 전 | 2908 | ||
| 297 | HTML | 17년 전 | 2650 | ||
| 296 | HTML | 17년 전 | 2357 | ||
| 295 | HTML | 17년 전 | 2459 | ||
| 294 | HTML | 17년 전 | 2704 | ||
| 293 | HTML |
|
17년 전 | 3072 | |
| 292 | HTML | 17년 전 | 2902 | ||
| 291 | HTML |
|
17년 전 | 3166 | |
| 290 | HTML |
jeans
|
17년 전 | 2591 | |
| 289 | HTML |
|
17년 전 | 4487 | |
| 288 | HTML | 17년 전 | 4644 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기