我正在尝试使用 xpath 表达式和 javascript从该页面http://www.money.pl/pieniadze/的表中提取几行。我可以将整个页面显示为弹出窗口,但我无法使用 document.evaluate() 评估 xpath 表达式;尝试使用 XPathResultType 但没有结果。有人可以帮忙吗?
这是我的背景页面:
<html><head><script>
...
var wholePage;
setInterval(fetch, 20000);
function fetch()
{
req = new XMLHttpRequest();
var url = "http://www.money.pl/pieniadze/";
req.open("GET", url);
req.onload = process;
req.send();
}
function process()
{
wholePage = req.responseText;
}
</script></head></html>
这是弹出页面:
<html><head><script>
...
onload = setTimeout(extract, 0);
function extract()
{
chrome.browserAction.setBadgeText({text: ''});
var bg = chrome.extension.getBackgroundPage();
var EurPlnPath = "//tr[@id='tabr_eurpln']";
var tempDiv = document.getElementById('current');
tempDiv.innerHTML = bg.wholePage;
var oneTopic = document.evaluate( EurPlnPath, bg.wholePage, null, XPathResult.ANY_TYPE, null)
var res = oneTopic.iterateNext();
}
</script></head>
<body>
<div id="current">
</div>
</body>
</html>