scrapeNewsImage static method
Implementation
static Future<Uint8List> scrapeNewsImage(RssItem rssItem) async {
try {
final body = await get(Uri.parse(rssItem.link!));
if (body.statusCode != 200) {
throw HttpException(
'Failed to scrape warning description, ${body.statusCode}');
}
final parsed = parse(utf8.decode(body.bodyBytes));
final parser = parsed.getElementsByTagName('img').first;
List<Element> results = parser.getElementsByClassName('portada');
final imageLink = await get(
Uri.parse("https://tib.org/${results.first.attributes["src"]}"));
return imageLink.bodyBytes;
} catch (e) {
throw Exception('Failed to scrape news image');
}
}