'How to get querySelectorAll from another webpage?
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|