Android 颤振-解析HTML数据时出错
我一直在尝试修改代码,以便在appsAndroid 颤振-解析HTML数据时出错,android,html,ios,dart,flutter,Android,Html,Ios,Dart,Flutter,我一直在尝试修改代码,以便在appslistView中可以看到来自的title和dateAdded 不幸的是,当我尝试运行下面编辑的代码时,我得到了下图中所述的错误 http.Response response = await http.get('https://www.virtualmoneysnews.com/category/bitcoin-news/'); //parse and extract the data from the web site dom.Document docum
listView
中可以看到来自的title
和dateAdded
不幸的是,当我尝试运行下面编辑的代码时,我得到了下图中所述的错误
http.Response response = await http.get('https://www.virtualmoneysnews.com/category/bitcoin-news/');
//parse and extract the data from the web site
dom.Document document = parser.parse(response.body);
document.getElementsByTagName('article').forEach((child) {
jobsList.add(Job(
title: child.getElementsByClassName('title').first.text,
dateAdded: child.getElementsByClassName('thetime date updated').last.text,
));
});
您可能应该删除此代码段,它依赖于您未填充的
item.location
Text(
item.location.trim(),
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
我将重构作业
类,将其重命名为文章
,标题
或故事
,即有意义的东西。例如:
class Story {
String title;
String dateAdded;
Story(this.title, this.dateAdded);
@override
String toString() => '$title $dateAdded';
}
然后可以编写您的刮码:
http.Response response = await http
.get('https://www.virtualmoneysnews.com/category/bitcoin-news/');
dom.Document document = parser.parse(response.body);
List<Story> stories = document
.getElementsByTagName('article')
.map((e) => Story(
e.getElementsByClassName('title').first.text,
e.getElementsByClassName('thetime date updated').last.text,
))
.toList();
http.Response=wait http
.get('https://www.virtualmoneysnews.com/category/bitcoin-news/');
documentdocument=parser.parse(response.body);
列表故事=文档
.getElementsByTagName('article'))
.map((e)=>故事(
e、 getElementsByClassName('title').first.text,
e、 getElementsByClassName('thetime date updated')。last.text,
))
.toList();
我需要在这里做什么?你能用完整的代码片段更新cde吗?在上面的代码片段中没有trim方法。我从来没有添加过trim方法,上面是我更改的唯一代码,你确认这是问题吗?这正是我要找的,谢谢你的帮助Richard