Flutter - Error parsing HTML data
1,537
You should probably remove this snippet, which relies on item.location
, which you aren't populating.
Text(
item.location.trim(),
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
I'd refactor the Job
class to rename it Article
, Headline
or Story
i.e. something meaningful. For example:
class Story {
String title;
String dateAdded;
Story(this.title, this.dateAdded);
@override
String toString() => '$title $dateAdded';
}
Your scraping code could then be written:
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();
Author by
Jake
Work email: jake(at)squaredsoftware.co.uk Please support me by downloading my new iOS application, travelrecce!
Updated on December 06, 2022Comments
-
Jake over 1 year
I've been trying to modify the code available here so that the
title
anddateAdded
from VMoneyNews is visible in the appslistView
.Unfortunately, when I try to run the following edited code I get the error stated in the Image below.
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, )); });
-
Jake over 5 yearsWhat do I need to do here?
-
ibhavikmakwana over 5 yearscan you update the cde with the full snippet, in above one there is no trim method.
-
Jake over 5 yearsI never added a trim method, above is the only code I changed, do you recon this is the issue?
-
-
Jake over 5 yearsThis is just what I’m looking for, thanks for the help Richard