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
번호 분류 제목 날짜 조회 수
897 HTMLPHPMSQL 지정한 이미지파일명을 출력 시키는 시험문제풀이 html 1 2023.12.13 50436
896 WindowsTip VBS) FTP.scriptlet and Shell.scriptlet 2013.09.21 48506
895 파이썬 python AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector' 해결방법 2023.05.07 47436
894 AutoHotKey AHK) 보안프로그램 등으로 화면복사(Printscreen) 안될때 사용방법 1 12 file 2012.11.21 47165
893 프로세스 pinomate.exe 프로세스 삭제방법 6 2011.02.13 45998
892 WindowsTip VBS) PostMessage or SendMessage to external program 2013.09.21 45965
891 컴퓨터잡담 [PHP] 원격지의 이미지 사이즈 구하는 방법 2 2009.08.11 44528
890 AutoHotKey Ahk) 웹페이지 감시결과에 따라 마이피플로 글 전송하기 12 file 2013.01.06 44022
889 컴퓨터잡담 emule 서버리스트 2010.11.10 43048
888 Excel Excel Vba) 셀의 행, 열(column, row) 주소 알아내기 또는 삽입하기 더불어 제어하기 2012.01.05 42969
887 AutoHotKey Autohotkey) 화면보호기(ScreenSaver) On/Off 방법 17 2012.03.16 40675
886 [Docs]스프레드시트 구글 스프레드시트에서 셀값이 특정일에서 현재일과 3일 이내의 범위에 들어오면 이메일을 발송하는 방법 2023.03.26 40418
885 컴퓨터잡담 2023-09-23 서버다운 후 복구완료 secret 2023.09.23 40394
884 Excel GET.CELL 매크로함수 응용 11 2012.07.16 40174
883 컴퓨터잡담 안드로이드 동영상 재생시 파란색 물음표 박스만 나올때 조치방법 2 file 2013.04.26 39285
882 컴퓨터잡담 URL Encoding 특수문자코드 4 2012.03.30 39022
881 컴퓨터잡담 mysql 날짜타입에 기본값으로 현재시간넣기 1 2009.12.07 38588
880 AutoHotKey ahk) 오토핫키 콤보박스 제어하기 file 2013.10.30 38175
879 WindowsTip 네트워크에 있는 다른 시스템과 ip 주소가 충돌합니다. 1 file 2013.03.29 38112
878 컴퓨터잡담 테블릿을 세컨트모니터로??? 2023.04.26 37992
Board Pagination Prev 1 2 3 4 5 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소