如何在 Flutter/Dart 中抓取 "style" 属性值

How to scrape "style" attribute value in Flutter/Dart

我正在尝试从网页中抓取数据。我想获得样式属性中的 URL(如图所示)

到目前为止我试过他的但它 returns 我空字符串

import 'dart:convert';
import 'package:html/dom.dart' as dom;
import 'package:html/parser.dart' as parser;
import 'package:http/http.dart' as http;


Future initiate() async {
  final response = await http.get('https://pixxelprecision.co.uk/portfolio');
  dom.Document document = parser.parse(response.body);

  final imgUrl = document.getElementsByClassName('w-ibanner-image');
  imgUrls = imgUrl.map((element) => element.attributes['style']).toList();

  print('URLs:  $imgUrls');

}

控制台:

style 属性最初没有值。页面渲染时由 JS 设置值。您可以尝试抓取 @data-bg

imgUrls = imgUrl.map((element) => element.attributes['data-bg']).toList();