<aside> 💡 RSS(Really Simple Syndication) 초간편배포 새로운 읽을 거리가 자주 갱신되는 블로그나 뉴스에서 주로 사용하는 XML 기반의 콘텐츠 배급포멧. 사이트에 RSS를 연동하면 운영중인 사이트의 내용이 다양해져 방문자 증대 효과

</aside>

조선닷컴 RSS

https://rssplus.chosun.com/

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

</head>
<body>
    <div class="wrap"></div>
</body>
</html>

<script>
        $(function(){
            $.ajax({
               /*  url:'https://www.chosun.com/arc/outboundfeeds/rss/category/national/?outputType=xml', */
                url:'news.php',
                dataType:'xml',
                success:function(data){
                    var $items=$(data).find('item');
                    console.log($items)
                    if($items.length>0){
                        //$items 배열에 에서 인덱스 0번부터 10번이전까지를(0이상 10미만) 반환하여 $items에 할당
                        $items=$items.slice(0,10);
                        var $ulTag=$('<ul/>');
                        $.each($items,function(i,o){
                            var $title=$(o).find('title').text();
                            var $link=$(o).find('link').text();

                            var $aTag=$('<a/>')
                            .attr({
                                'href':$link,
                                'target':'_blank'
                            })
                            .text($title);
                            var $liTag=$('<li/>')
                            .append($aTag);
                            $ulTag.append($liTag);
                        })
                        $('.wrap').append($ulTag)
                    }
                }
            });
        })
    </script>

콘솔오류확인

동일출처 원칙에 따라 보안에 막혀 불러오지 못함

동일출처 원칙에 따라 보안에 막혀 불러오지 못함

news.php

<?php
    //cURL 메서드를 사용해 교차도메인 데이터 불러오기
    $ch = curl_init();  //cURL을 초기화, 세션생성
    //curl_setopt(세션,옵션,값) cURL 세션의 옵션 설정

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//SSL인증서검사여부
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//결과값을 받을것인지 여부
    curl_setopt($ch, CURLOPT_HEADER, 0);    //헤더정보출력여부 0,false
    curl_setopt($ch, CURLOPT_URL,
    'https://www.chosun.com/arc/outboundfeeds/rss/category/national/?outputType=xml');  //접속 URL 설정

    //crul_exec: cURL 세션실행
    $url_source=curl_exec($ch); 
    //curl_close : cURL 세션 종료
    curl_close($ch);

    echo $url_source;
?>

서버에 모든 파일을 등록후 확인