我已经在Amazon.co.uk上加载了https页面,并且希望显示使用'GM xmlhttpRequest'来请求链接上的项目的价格页。使用GM xmlhttpRequest而不是iframe来显示来自外部页面的相关信息
我到目前为止一直在做
我tried to use an 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 xmlhttp请求获取页面
背景:我正在使用类似于GreaseMonkey的东西
这是Greasekit Fluid.app(这是非常古老的,但我必须使用它)。您可能甚至不需要知道它与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;
}
});
我刚刚得到的“读取......”的邮件,但是我还没有研究过你的注解;可能会有一些调整,我需要让我只是检查错误控制台和它说'的ReferenceError:能否” t找到变量:GM_xmlhttpRequest' –
[Greasekit支持GM_xmlhttpRequest](http://8-p.info/greasekit/changes.html),但那个错误表明Fluid不会。联系Fluid。也可能有一个设置你有在Fluid选项中制作,尝试在脚本的元数据部分添加'// @grant GM_xmlhttpRequest'。 –