我正在尝试获取包含产品的Google购物页面,我需要获取缩略图。问题在于,以base64编码的图像和响应在图像的src属性中包含缩短的代码。除了完整的代码,还有///////
src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
这是我的代码
let title = "RockDove Men's Original Two-Tone Memory Foam Slipper";
let urlparse = "https://www.google.com/search?tbm=shop&tbs=vw:g&q=" +
encodeURIComponent(title);
fetch(urlparse)
.then(data => {
return data.text();
})
.then(htmlString => {
// parsing html string into DOM
let parser = new DOMParser();
let doc = parser.parseFromString(htmlString, "text/html");
// retrieve products data from DOM
let products = doc.querySelectorAll(".sh-pr__product-results > div");
let productsArr = Array.prototype.slice.call(products);
let productsData = productsArr.map(el => {
return el.querySelector(".sh-dgr__thumbnail").innerHTML;
});
console.log(productsData);
});
我还尝试使用.blob()而不是.text(),然后使用FileReader从 Blob对象,但结果相同