【发布时间】:2019-05-08 17:12:54
【问题描述】:
我们正在尝试从通过 XHR GET 请求远程获取的完整 HTML 页面访问各种 DOM 元素。
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.example.com/test.html", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var newdom = xhr.responseText;
var val_result = newdom.a_div.innerText;
// we want to access the text within this div, from the fetched html page?
}
}
xhr.send();
有什么想法吗?
【问题讨论】:
-
字符串是newdom吗?是字符串dom吗?
-
如果 newdom 是一个 dom 字符串,请阅读这个问题的答案stackoverflow.com/questions/494143/…
标签: javascript dom xmlhttprequest html-parsing