html - 如何在flutter中解析特定数据html
问题描述
我想从 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);
解决方案
var rows=foldertree.getElementsByTagName("ul")[0].getElementsByTagName("li");
var spnameList = rows.map((element) => element.attributes['spname']).toList();
推荐阅读
- javascript - TypeError:无法读取未定义和 m.ban 的属性“forEach”
- c# - 没有接口时如何模拟 SecretClient?
- react-native - 当 ArrayBuffer 不存在时从获取响应中读取二进制数据
- python - 根据列号和条件删除文本文件中的记录 - python
- node.js - 与 create-react-app 相关的 Heroku 部署问题
- .net - 如何仅从连接字符串中检测 DbConnection 类型名称
- c# - Oracle ORA-06502 c# 中的过程出现数值或值错误
- angular - 如何在离子日期时间组件中设置最大秒数
- flutter - 如何在 Flutter 中创建带边框的圆形按钮?
- r - R 日期未在 tableOutput 中正确显示(闪亮)