I am using the below function in Flutter (package: webview_flutter) to extract a specific image of a product from Amazon website. But I am getting null value
Below is my function. It returns correct values when I give 'document.cookie' and 'document.location.href' in the runJavaScriptReturningResult function. But when I give a complex path, it's unable to get the value of the image url.
Future<void> _onGetFocusImage(WebViewController controller) async {
final focusImage = await controller
.runJavaScriptReturningResult('document.getElementById("unrolledImgNo0").querySelector("img").getAttribute("src")');
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('$focusImage'),
),
);
print("url is $focusImage");
}
I don't believe that the parameter to below library function is a problem. As I checked that argument is definitely string type. Where am I going wrong? Please suggest why for certain document attributes I am getting the value when I call below function but for other document attributes I am not getting any value
Future<Object> runJavaScriptReturningResult(String javaScript) {
return platform.runJavaScriptReturningResult(javaScript);
}
You can for any product URL. But i checked for below link
https://www.amazon.in/dp/B07XKCXPNN/ref=sspa_dk_detail_7?psc=1&pd_rd_i=B07XKCXPNN&pd_rd_w=xfA7J&content-id=amzn1.sym.0fcdb56a-738b-4621-9da7-d47193883987&pf_rd_p=0fcdb56a-738b-4621-9da7-d47193883987&pf_rd_r=BEJ1AGY5NZDQHAP376T3&pd_rd_wg=BZo9B&pd_rd_r=f3666f20-3db5-486c-aac2-cc6abcb2561d&s=apparel&sp_csd=d2lkZ2V0TmFtZT1zcF9kZXRhaWwy
