我在 Amazon.co.uk 上加载了一个 https 页面,我希望在链接页面上显示使用“GM xmlhttpRequest”来请求商品的价格。
到目前为止我一直在做什么
我尝试使用 iFrame来显示窗口:
var prodLinks = $("td.product_description a:contains('View Amazon Product Page')");
if (prodLinks.length) {
var iframeSrc = prodLinks[0].href;
iframeSrc = iframeSrc.replace (/http:\/\//, "https://")
$("body").append ('<iframe id="gmIframe" src="' + iframeSrc + '"></iframe>');
$("#gmIframe").css ( {
"position": "absolute",
"bottom": "1em",
"left": "2em",
"height": "25%",
"width": "84%",
"z-index": "17",
"background": "#00FF00"
} );
}
这种方法的问题是,虽然它有效,但 iFrame 的内容太杂乱,所以我一眼看不到我需要什么。
我想看的东西
让我们假设链接页面是https://www.amazon.co.uk/gp/product/B001AM72BM/
来自上述页面的相关 HTML 片段:
<tr id="actualPriceRow">
<td id="actualPriceLabel" class="priceBlockLabelPrice">Price:</td>
<td id="actualPriceContent"><span id="actualPriceValue"><b class="priceLarge">£2.85</b></span>
<span id="actualPriceExtraMessaging">
确切地说,我如何使用 GM xmlhttpRequest 来获取页面
背景:我正在使用类似于 GreaseMonkey 的东西
这是 Fluid.app 上的Greasekit(它很旧,但我必须使用它)。您可能甚至不需要知道这一点,因为它与 Greasekit 非常相似。所以,为了这个问题的目的,你可以假装它是。
我的回答尝试
我会尝试:
GM_xmlhttpRequest({
method: "GET",
url: "https://www.amazon.co.uk/gp/product/B001AM72BM/",
onload : function(response) {
// do something with the result here
document.getElementByClass(‘priceLarge').innerHTML = response.responseText;
}
});