使用诸如 cURL 或(在 PHP 中)stream contexts/file_get_contents
之类的东西来获取页面的起始 HTML 标记非常简单,但是如今,由于 JS 严重控制了如此多的页面,即使您获得了页面的起始标记,您仍然无法轻易确定页面的实际构成(因为页面的大部分内容是由运行客户端的 JS 构成的)。
那么,是否有可能在页面的所有on-load JS执行后,通过cURL等方式获取页面的整个DOM结构?
(作为额外信息,我知道您可以使用 Chrome 开发工具等获取 DOM 结构,但我想知道是否有任何方法可以使该过程自动化。)
非常感谢。
最佳答案
您必须在浏览器中运行它,然后获取 document.documentElement.outerHTML
的内容。
我认为仅在 PHP 中这是不可能的。你必须使用:
-
PhantomJS is a headless WebKit scriptable with a JavaScript API. Access and manipulate webpages with the standard DOM API, or with usual libraries like jQuery.
或 SlimerJS .
SlimerJS is similar to PhantomJs, except that it runs Gecko, the browser engine of Mozilla Firefox, instead of Webkit.
关于javascript - 是否可以在所有JS执行完后获取页面的DOM结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18264504/