如何从另一个网页中获取QuerySelectorall?
我正在尝试使用HTML DOM从另一个网页获取数据。我尝试了另一个stackoverflow问题( querySelectorall()到另一页)但是这对我不起作用:
let url = "[URL here]"
let xml = new XMLHttpRequest()
xml.onreadystatechange = function() {
if (xml.readyState == 4) {
let container = document.implementation.createHTMLDocument().documentElement
container.innerHTML = xml.responseText
let nodeList = container.querySelectorAll('.msDetails-Row')
console.log(nodeList)
}
}
xml.open("GET", url, false)
xml.send(null)
Nodelist在控制台日志中为空。但是,当我运行代码时,QuerySelectorAll('。MSDETAILS-ROW'),在实际URL上可以使用。
I'm trying to get data from another webpage, using the HTML DOM. I tried code from another StackOverflow question (querySelectorAll() to html from another page) but it's not working for me:
let url = "[URL here]"
let xml = new XMLHttpRequest()
xml.onreadystatechange = function() {
if (xml.readyState == 4) {
let container = document.implementation.createHTMLDocument().documentElement
container.innerHTML = xml.responseText
let nodeList = container.querySelectorAll('.msDetails-Row')
console.log(nodeList)
}
}
xml.open("GET", url, false)
xml.send(null)
The nodeList is empty in the console log. However, when I run the code, querySelectorAll('.msDetails-Row'), on the actual URL, it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论