简体   繁体   English

使用 Node.js 监控第三方流量的最佳方式是什么?

[英]What's the best way to monitor third-party traffic with Node.js?

I'm trying to identify all outbound http requests for resources on third-party sites using Node.js.我正在尝试使用 Node.js 识别对第三方站点上的资源的所有出站 http 请求。 I've started using Phantomjs (and phantomjs-node) which has network monitoring features, but I'm finding it unreliable for many sites.我已经开始使用具有网络监控功能的 Phantomjs(和 phantomjs-node),但我发现它对许多站点都不可靠。

I've seen tools like Charles and Fiddler, but I'm trying to incorporate the third-party http requests into my own Node.js app.我见过像 Charles 和 Fiddler 这样的工具,但我正在尝试将第三方 http 请求合并到我自己的 Node.js 应用程序中。

Is there any other way to approach this without using a headless browser?有没有其他方法可以在不使用无头浏览器的情况下解决这个问题?

I am not really a fan of using phantomjs from Node.我并不是很喜欢使用 Node.js 中的 phantomjs。 Essentially PhantomJS has its own Event Loop and Node JS has its own and most of the npm modules(including phantomjs-node) available online will use some sort of messaging(Websocket etc.) to communicate between the two.本质上,PhantomJS 有自己的事件循环,Node JS 有自己的,大多数在线提供的 npm 模块(包括 phantomjs-node)将使用某种消息传递(Websocket 等)在两者之间进行通信。

Now back to your original problem.现在回到你原来的问题。

You have a few options:您有几个选择:

  1. If you want to just capture requests from a web page for a few executions you may as well use a Chrome or Firefox extension.如果您只想从网页中捕获请求进行几次执行,您也可以使用 Chrome 或 Firefox 扩展程序。 In Firefox you can Use Firebug( http://getfirebug.com/ ) to capture net and XHR requests.在 Firefox 中,您可以使用 Firebug( http://getfirebug.com/ ) 来捕获网络和 XHR 请求。 In Chrome you can use the Chrome Dev Tools to capture requests and right click Save the request as JSON.在 Chrome 中,您可以使用 Chrome Dev Tools 捕获请求并右键单击将请求另存为 JSON。
  2. You can write your own Firefox extension which will capture the Net requests and log them.您可以编写自己的 Firefox 扩展来捕获网络请求并记录它们。
  3. If you want to use PhantomJS I would recommend using PhantomJS 2( since it uses the latest version of WebKit).如果您想使用 PhantomJS,我建议您使用 PhantomJS 2(因为它使用最新版本的 WebKit)。 I would also recommend using it directly instead of from NodeJS just to reduce the complexities.我还建议直接使用它而不是 NodeJS 来降低复杂性。

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

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