scrapeNewsDescription static method
Implementation
static Future<List<String>?> scrapeNewsDescription(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 parser = parse(utf8.decode(body.bodyBytes));
List<String> bodyText = [];
final div =
parser.getElementsByClassName('news-container-content-body').first;
List<Element> results = div.querySelectorAll('p');
for (var value in results) {
bodyText.add(value.text.trim());
}
return bodyText;
} catch (e) {
throw Exception('Failed to scrape news description');
}
}