본문 바로가기
프로그래밍/React Native(2018)

[React Native] HTML에서 parsing(parse)해오는 방법

by 쿼카퀀트 2019. 9. 29.
728x90
fetch("https://stackoverflow.com/questions/38343951/how-do-i-parse-an-html-file-in-react-native")
    .then((response) => response.text())
    .then((text)=>{ console.log(text) })

 

위처럼 fetch(url)을 하면 promise로 response를 준다. 여기서 response.text()를 하면

 

아래와 같이 HTML을 받아올 수 있다.

 

<!DOCTYPE html>

 

    <head>

 

        <title>javascript - How do I parse an HTML file in React Native? - Stack Overflow</title>

       

       

        <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">

        <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">

 

 

        <meta property="og:type" content= "website" />

       

        <meta property="og:site_name" content="Stack Overflow" />

       

        <meta name="twitter:card" content="summary"/>

        <meta name="twitter:domain" content="stackoverflow.com"/>

        <meta name="twitter:title" property="og:title" itemprop="title name" content="How do I parse an HTML file in React Native?" />

        <meta name="twitter:description" property="og:description" itemprop="description" content="How can I get an HTML file from file system and parse specific elements from it.

 

For example, given the html snippet below, how can I extract the table content and render it?

 

 

 

&amp;lt;html&amp;gt;

&amp;l..." />

       

       

    

   

       

    

            <link rel="alternate" type="application/atom+xml" title="Feed for question &#39;How do I parse an HTML file in React Native?&#39;" href="/feeds/question/38343951">

            <meta name="twitter:app:country" content="US" />

            <meta name="twitter:app:name:iphone" content="Stack Exchange iOS" />

            <meta name="twitter:app:id:iphone" content="871299723" />

            <meta name="twitter:app:url:iphone" content="se-zaphod://stackoverflow.com/questions/38343951/how-do-i-parse-an-html-file-in-react-native" />

            <meta name="twitter:app:name:ipad" content="Stack Exchange iOS" />

            <meta name="twitter:app:id:ipad" content="871299723" />

            <meta name="twitter:app:url:ipad" content="se-zaphod://stackoverflow.com/questions/38343951/how-do-i-parse-an-html-file-in-react-native" />

            <meta name="twitter:app:name:googleplay" content="Stack Exchange Android">

           

            <meta name="twitter:app:id:googleplay" content="com.stackexchange.marvin">

        <script>

 

            StackExchange.ready(function () {

                                    

                    StackExchange.using("snippets", function () {

                        StackExchange.snippets.initSnippetRenderer();

                    });

                    

 

                StackExchange.using("postValidation", function () {

                    StackExchange.postValidation.initOnBlurAndSubmit($('#post-form'), 2, 'answer');

                });

 

                

                StackExchange.question.init({showAnswerHelp:true,totalCommentCount:0,shownCommentCount:0,highlightColor:'#F4A83D',backgroundColor:'#FFF',questionId:38343951});

 

                styleCode();

 

                    StackExchange.realtime.subscribeToQuestion('1', '38343951');

                                                    StackExchange.using("gps", function () { StackExchange.gps.trackOutboundClicks('#content', '.post-text'); });

 

            });

        </script>

 

        

        

        

        

        

        

                <script>

        StackExchange.init({"locale":"en","serverTime":1532482651,"routeName":"Questions/Show","stackAuthUrl":"https://stackauth.com","networkMetaHostname":"meta.stackexchange.com","site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers","isNoticesTabEnabled":true,"enableNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"id":1,"childUrl":"https://meta.stackoverflow.com","enableSocialMediaInSharePopup":true,"enableTagWatchingPopup":true,"protocol":"https"},"user":{"fkey":"2819d06861610192ba33b0c48e46f7cc465aff

728x90

댓글