如何在React Native中解析HTML文件? [英] How do I parse an HTML file in React Native?
本文介绍了如何在React Native中解析HTML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从文件系统中获取HTML文件并从中解析特定元素。
例如,给定下面的html片段,我该如何提取表格内容和渲染吗?
< html>< div> < H1>报头LT; / H1> < table id =aborder =1> <的第i;号< /第> < th>内容A< / th> < th> contetn A< / th> < th>内容A< / th> < TR> < TD→1< / TD> < TD>一种与LT; / TD> < TD>一种与LT; / TD> < TD>一种与LT; / TD> < / TR> <的第i;号< /第> < th>内容B< th> < th>内容B< th> < th>内容B< th> < TR> < TD→1< / TD> < TD> b将; / TD> < TD> b将; / TD> < TD> b将; / TD> < / TR> < /表>< / DIV><峰; br><页脚>页脚< /页脚>< / HTML>
解决方案
只需使用fetch()下载HTML,使用 fast-html-parser ,将结果写入状态并使用 WebView
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?
<html>
<div>
<h1>header</h1>
<table id="a" border="1">
<th>Number</th>
<th>content A</th>
<th>contetn A</th>
<th>content A</th>
<tr>
<td>1</td>
<td>a</td>
<td>a</td>
<td>a</td>
</tr>
<th>Number</th>
<th>content B</th>
<th>content B</th>
<th>content B</th>
<tr>
<td>1</td>
<td>b</td>
<td>b</td>
<td>b</td>
</tr>
</table>
</div>
<br>
<footer>footer</footer>
</html>
解决方案
Just download HTML with fetch(), parse it using fast-html-parser, write result to state and render that state with WebView
这篇关于如何在React Native中解析HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文