我正在开发一个页面,该页面读取另一个页面的源,并且需要从该页面中提取某些信息。目前,我有一个用数据捕获实时源代码的项目,但是我一辈子都无法弄清楚如何将该字符串转换为文档。
我使用文档的理由是我需要使用getElementById
等来获取这些项目的值(value)。
我尝试了什么?
任何帮助将不胜感激。
相关代码:
$.ajax({
method: "GET",
dataType: '',
crossDomain: true,
xhrFields: {
withCredentials: true
},
success: function(res) {
//shows the entire source just fine.
console.log("Value of RES: " + res);
bootbox.hideAll();
//shows a "truncated" copy of the source
alert(res);
$("#hiddendiv").html(x);
var name = document.findElementById("myitem");
alert(name);
},
最佳答案
在文档上创建一个隐藏的IFRAME。然后,将该IFRAME的内容设置为要查询的HTML。查询时,使用JavaScript定位该IFRAME。请参阅How can I access iframe elements with Javascript?了解如何。