So we all know that the DOM
(Document Object Model) is an interface that represents HTML pages in web browsers and that you can interact with it using JavaScript.
And now and then I read comments about needing a web browser to use the DOM. But is this true?
Aren't there other implementations of the DOM such as in server side JavaScript engines, screen scrapers, unit testing frameworks, other programming languages besides JavaScript, etc?
Or has this really never been done?
And now and then I read comments about needing a web browser to use the DOM. But is this true?
Of course not. Your understanding is correct.
The term you're looking for is "headless browser" and yes they do exist. No need to spin up an instance of IE, Chrome, or firefox to execute JavaScript and mine data from the DOM. Check out Phantom.js or Zombie.js.
Plenty of other questions related to this topic:
来源:https://stackoverflow.com/questions/12006490/are-there-implementations-of-the-w3c-dom-other-than-in-web-browsers