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?
&lt;html&gt;
&l..." />
<link rel="alternate" type="application/atom+xml" title="Feed for question 'How do I parse an HTML file in React Native?'" 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
'프로그래밍 > React Native(2018)' 카테고리의 다른 글
[React Native] Object를 storage에 저장하는 방법 (0) | 2019.09.29 |
---|---|
[React Native] mobX를 사용한 state management (0) | 2019.09.29 |
[React Native] Animate 효과 주기 (0) | 2019.09.29 |
[React Native] createStackNavigator를 사용해 다른 페이지로 이동하도록 하는 방법 (0) | 2019.09.28 |
[React Native] Android의 findViewById 처럼 Component의 id를 등록해주고 찾게해주는 방법 (0) | 2019.09.28 |
댓글