简体   繁体   English

使用node.js监视服务器端的DOM更改

[英]Monitoring DOM changes on the server side with node.js

I'm wondering if its possible to load a website like the twitter search results page using node.js with jsdom and still be able to detect any changes in the DOM after the initial render. 我想知道是否可以使用带有jsdom的node.js加载像twitter搜索结果页面这样的网站,并且仍然能够在初始渲染后检测DOM中的任何更改。

Example: 例:

Initial page 初始页面

Modified page 修改页面

Thanks for your help. 谢谢你的帮助。

If you want to detect what changed in the DOM tree you will need to understand the minified Twitter's javascript code and properly intercept the events or callbacks. 如果你想检测DOM树中发生的变化,你需要了解缩小的 Twitter的javascript代码并正确拦截事件或回调。 I don't suggest you this approach because js code that works perfectly in browser may break when using jsdom. 我不建议你使用这种方法,因为在使用jsdom时,在浏览器中完美运行的js代码可能会中断。 For instance, when I was trying to do some server side scrapping with jquery I got stuck with this bug that in most browsers is definitely not an issue. 例如,当我试图用jquery做一些服务器端报废时,我遇到了这个错误 ,在大多数浏览器中肯定不是问题。

For the time being, what I recommend is that you consume the Search API directly from Twitter which is a more straightforward approach. 目前,我建议您直接从Twitter使用Search API ,这是一种更直接的方法。

Hope it helps! 希望能帮助到你!

Certainly the best approach is to leverage the Search API (or whatever relevant API) from Twitter to accomplish this. 当然,最好的方法是利用Twitter上的Search API(或任何相关API)来实现这一目标。

But if, for some other project, you want to host a full browser environment (JS + dom + renderer) that remains alive and lets you interact with it, the PhantomJS project might work: 但是,对于某些其他项目,如果您希望托管一个完整的浏览器环境(JS + dom +渲染器)并保持活动并允许您与之交互,则PhantomJS项目可能会起作用:

http://code.google.com/p/phantomjs/ http://code.google.com/p/phantomjs/

It hosts a WebKit instance for automation. 它托管一个用于自动化的WebKit实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM