Skip to content
조회 수 33674 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

네이버 많이 본 뉴스 PHP로 RSS 출력 만들기


네이버의 http://news.naver.com/main/ranking/popularDay.nhn?date=20090805&sectionId=000&rankingType=popular_day 가보시면 하루동안 가장 많이 본 뉴스

리스트가 나옵니다. 최상위 5개는 이미지도 나와서 보기가 좋습니다.


주소 중 sectionId= 부분에서 000은 


000="전체" 100 = "정치" 101="경제" 102="사회" 103="생활문화" 104="세계" 105="IT/과학" 107="스포츠" 106="연예" 115="TV"


이렇습니다.


아래의 내용을  test.php로 저장한 뒤 문서저장한 위치가 localhost 이라면


localhost/test.php?uuu=000     => 전체

localhost/test.php?uuu=100     => 정치


등으로 변수를 주어 사용할 수 있습니다.

uuu는 제가 변수줄때 자주쓰는거라 그냥 별뜻없이 uuu를 선택했습니다. ^^;;




//======================================================================================


<?

// echo date("Ymd",strtotime("now"));// 앞의 슬러쉬 // 를 제거해보세요.^^;;
$dat = date("Ymd",strtotime("now"));
// 000="전체" 100 = "정치" 101="경제" 102="사회" 103="생활문화" 104="세계" 105="IT/과학" 107="스포츠" 106="연예" 115="TV"
//http://news.naver.com/main/ranking/popularDay.nhn?date=20090805&sectionId=101&rankingType=popular_day

 

$a = file('http://news.naver.com/main/ranking/popularDay.nhn?date='.date("Ymd",strtotime("now")).'&sectionId='.$uuu.'&rankingType=popular_day');

$bae = 0;

for($i=0;$i<count($a);$i++)
 {
 if(ereg('<div class="ranking_relation">',$a[$i])) $cc = 1;
 if(ereg('<div class="list_body ranking_body">',$a[$i])) $cc = 0;

 if($cc == 1)
  {
  if(ereg('<img src="',$a[$i]))
    {
    $imga = explode('<img src="',$a[$i]);
    $imga = explode('"',$imga[1]);
    $img[$bae] = $imga[0];
//    echo $img[$bae];
    $linka = explode('<a href="',$a[$i-1]);
    $linka = explode('">',$linka[1]);
    $link[$bae] = $linka[0];

    $titlea = explode('alt="',$a[$i+1]);
    $titlea = explode('"',$titlea[1]);

    $title[$bae] = $titlea[0];

//    echo $link[$bae];
//    echo $title[$bae];

    $bae++;
    }
  }
 } //for_end

 

$content .= '<?xml version="1.0"?>'.chr(13);
$content .= ' <rss version="2.0">'.chr(13);
$content .= ' <channel xmlns:psl="http://rainbow.daum.net/psl">'.chr(13);
$content .= '        <title>네이버 많이 본 뉴스</title>'.chr(13);
$content .= '        <link>http://kin.naver.com/open_home.php</link>'.chr(13);
$content .= '  <description>네이버 많이 본 뉴스</description>'.chr(13);
$content .= '        <pubDate></pubDate>'.chr(13);
$content .= '  <language>ko</language>'.chr(13);
$content .= '  <copyright>Copyright ⓒ NHN Corp. All Rights Reserved.</copyright>'.chr(13);
$content .= '  <webMaster>master@naver.com</webMaster>'.chr(13);
$content .= '  <generator>Naver</generator>'.chr(13);
$content .= '  <docs></docs>'.chr(13);
$content .= '  <ttl>20</ttl>'.chr(13);
$content .= '  <image>'.chr(13);
$content .= '   <url>http://static.naver.com/common/snb/090513/h_naver2.gif</url>'.chr(13);
$content .= '   <title>Naver RSS</title>'.chr(13);
$content .= '   <link>http://www.naver.com</link>'.chr(13);
$content .= '  </image>'.chr(13);


for($i=0;$i<count($title);$i++)
 {

  $content .= '  <item>'.chr(13);
  $content .= '  <title>'.$title[$i].'</title>'.chr(13);
  $content .= '  <link>http://kin.naver.com'.htmlspecialchars($link[$i]).'</link>'.chr(13);
  $content .= '  <description><img src="'.$img[$i].'"></description>'.chr(13);
  $cate = explode(',',$tag[$i]);

  if($cate[0]) {$content .= '  <category>'.$cate[0].'</category>';}
  if($cate[1]) {$content .= '  <category>'.$cate[1].'</category>';}
  if($cate[2]) {$content .= '  <category>'.$cate[2].'</category>';}
  if($cate[3]) {$content .= '  <category>'.$cate[3].'</category>';}
  if($cate[4]) {$content .= '  <category>'.$cate[4].'</category>';}

//  for($ii=0;$ii<count($cate);$i++)
//   { echo '<category>'.$cate[$ii].'</category>'; }


  $content .= '  </item>'.chr(13);
 }//for_end


$content .= '</channel>'.chr(13);
$content .= '</rss>';

print $content;

 

?>








로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
157 컴퓨터잡담 Windows Movie Maker 2.1 다운로드 2 2 file 2010.09.11 22457
156 컴퓨터잡담 XP윈도우가 버벅 거릴때 시스템 파일 복구하기 1 2010.09.11 11273
155 컴퓨터잡담 동영상 제작프로그램, 파워디렉터(POWER DIRECTOR) 1 2 2010.09.10 20214
154 컴퓨터잡담 이전 버전의 Office로 Office 2007 파일을 여는 방법 1 2010.09.04 11301
153 컴퓨터잡담 Excel에서 틀 고정 방법 2010.09.04 18628
152 컴퓨터잡담 아파치서버에서 시작시 무엇을 불러들이나? httpd -l 1 2 2010.09.04 9780
151 컴퓨터잡담 [악성코드제거] 가짜백신에 속지말고 MS정품을 이용하자. 2010.09.02 10318
150 컴퓨터잡담 무선랜 비밀번호 모음 3 2010.08.26 16895
149 컴퓨터잡담 [악성코드] 컴퓨터가 주기적으로 꺼지는 현상 2 2010.08.24 12217
148 컴퓨터잡담 hMailServer - 설치시 주의 핵심사항 1 2010.08.24 103067
147 컴퓨터잡담 [윈도우 웹서버] hmailserver 1 1 2010.08.22 23389
146 컴퓨터잡담 부팅시마다 체크디스크 실행되는 경우 설정방법 2010.08.21 26563
145 컴퓨터잡담 Tips N Tricks Process Listing - Using third party DLL! 2010.08.14 20424
144 컴퓨터잡담 [autohotkey] 시스템 레지스트리 수정, 삭제 1 3 2010.08.14 8062
143 컴퓨터잡담 [autohotkey] 시스템 레지스트리 수정, 삭제 2010.08.14 8486
142 컴퓨터잡담 [잦은오류해결] 오류발생을 알려주는 drwtsn32.exe 때문에 다운? 차라리 없애버리자. 2010.08.12 5838
141 컴퓨터잡담 [악성코드퇴치] 악성코드 처리 방법 1 2010.08.12 9902
140 컴퓨터잡담 [악성코드퇴치] hosts 파일로 경로납치 현상 방지 1 2010.08.12 14026
139 컴퓨터잡담 [악성코드퇴치] NSLOOKUP 경로 확인으로 가로채기 하기 1 2010.08.12 14605
138 컴퓨터잡담 악성코드 mus.exe 제거하기 2010.08.11 16034
Board Pagination Prev 1 ... 37 38 39 40 41 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소