【问题标题】:how to parse specific data html in flutter如何在flutter中解析特定数据html
【发布时间】:2021-04-12 08:11:27
【问题描述】:

我想从 html 文本中获取文件夹名称列表。

我正在从 api 获取 html,它看起来像这样:

<ul><li class='expanded' data-icon='folder_docs.gif' id='fol_1' onclick='getli(this.id,0)' dcr='7/26/2017 2:42:47 PM' spname='مستندات'>مستندات<ul><li class='' id='fol_20'onclick='getli(this.id,0)' f_pertype='2' dcr='7/5/2019 10:29:02 AM' is_Wr='True' own='13781' spname='test'> test<ul><li class='' id='fol_27'onclick='getli(this.id,0)' f_pertype='2' dcr='9/3/2020 9:10:26 AM' is_Wr='True' own='13781' spname='test2'> test2<ul><li class='' id='fol_29'onclick='getli(this.id,0)' f_pertype='2' dcr='9/15/2020 3:2…ue' own='13781' spname='test'> test</li><li class='' id='fol_36'onclick='getli(this.id,0)' f_pertype='2' dcr='12/7/2020 10:40:08 AM' is_Wr='True' own='13781' spname='file1'> file1</li><li class='' id='fol_37'onclick='getli(this.id,0)' f_pertype='2' dcr='12/14/2020 9:09:18 AM' is_Wr='True' own='13781' spname='test'> test</li><li class='' id='fol_38'onclick='getli(this.id,0)' f_pertype='2' dcr='12/23/2020 12:23:14 PM' is_Wr='True' own='13781' spname='createdfromMobile'> createdfromMobile</li></ul></li></ul>"

我想从这个 html 中获取所有的“spname”数据。

这是我所做的:

var foldertree = parse(htmltext.toString());
List<String> data = [];
data.add(foldertree.getElementsByClassName("class")[0].innerHtml);
var temp  = foldertree.getElementsByClassName("expanded")[0];      
data.add(temp.innerHtml.substring(0, temp.innerHtml.indexOf("<li>")));           
data.add(temp.getElementsByTagName("spname")[0].innerHtml);                                           
print(data.toString);   

【问题讨论】:

    标签: html json flutter dart


    【解决方案1】:
    var rows=foldertree.getElementsByTagName("ul")[0].getElementsByTagName("li");
    var spnameList = rows.map((element) => element.attributes['spname']).toList();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2020-10-13
      • 1970-01-01
      • 2021-02-01
      • 2020-08-21
      相关资源
      最近更新 更多