Let's assume I browse a specific web page that uses JavaScript to update its view constantly (using Web 2.0 techniques to talk to their server to retrieve updates of data).
假设我浏览一个使用JavaScript不断更新其视图的特定网页(使用Web 2.0技术与其服务器通信以检索数据更新)。
Now I like to run some code on my own computer that monitors the contents and alerts me if some specific data appears on the page, so that I could record that data, for instance.
现在,我喜欢在我自己的计算机上运行一些监视内容的代码,并在页面上显示某些特定数据时提醒我,以便我可以记录这些数据。
I am looking for ways to accomplish that. Since it's a private project, I am flexible in the choices of my tools (I can program in C and REALbasic, and could manage a little JavaScript as well). The only thing out of my control is the page I want to monitor.
我正在寻找实现这一目标的方法。由于它是一个私有项目,我可以灵活选择我的工具(我可以用C和REALbasic编程,也可以管理一些JavaScript)。唯一不受我控制的是我要监控的页面。
I would prefer a solution I can employ on Mac OS X, but Linux or Windows would be feasible, too.
我更喜欢我可以在Mac OS X上使用的解决方案,但Linux或Windows也是可行的。
First, I wonder if there are already solutions for this out there. Something like a user-scriptable web browser, for instance.
首先,我想知道是否已有解决方案。例如,类似于用户可编写脚本的Web浏览器。
If that's not available, I wonder how to best approach this by programming it myself. E.g, can someone tell me if Apple's Webkit allows me to introspect a dynamically updating web page?
如果那不可用,我想知道如何通过自己编程来最好地解决这个问题。例如,有人可以告诉我Apple的Webkit是否允许我内省动态更新的网页?
As a last resort, I guess I would have to insert my own javascript code into the viewed webpage (I could do that easily, I think, at time of loading the page over the internet), and then have that script run periodically, introspecting the page it's in. The only thing I don't know in this case is how to get it to communicate with the outside, i.e. my computer. I could certainly write an app that it could try talking to, but how could it at all access my computer resources to establish such a communication? As far as I understand the sandboxing of web pages, they cannot read/write local files or communicate with a socket on the computer they're running on, or can they?
作为最后的手段,我想我必须将自己的javascript代码插入到查看的网页中(我认为,在通过互联网加载页面时我可以轻松地做到这一点),然后定期运行该脚本,反省它所在的页面。在这种情况下我唯一不知道的是如何让它与外部通信,即我的计算机。我当然可以编写一个可以尝试与之交谈的应用程序,但它怎么可以访问我的计算机资源来建立这样的通信呢?据我所知,网页的沙盒,他们无法读取/写入本地文件或与他们正在运行的计算机上的套接字通信,或者他们可以吗?
So, any ideas are welcome, as long as they're clear of the concept that I have to let a browser or its engine render the page and run the page's Javascripts.
所以,任何想法都是受欢迎的,只要他们清楚我必须让浏览器或其引擎呈现页面并运行页面的Javascripts。
3 个解决方案
#1
This sounds like it could be pretty easy using Jetpack in Firefox.
这听起来在Firefox中使用Jetpack非常容易。
You can create browser extensions using Javascript - it's still in alpha but looks to be workable (and awesome)...
您可以使用Javascript创建浏览器扩展 - 它仍处于alpha状态但看起来可行(并且非常棒)......
#2
I agree you could definitely do this with a Firefox extension (I haven't used JetPack, and I don't know if it could handle this). Firefox extensions can communicate with arbitrary XPCOM components. So the extension would have a small JavaScript part to suck the data out of the DOM, then communicate with a C(++) XPCOM component to do anything else.
我同意你肯定可以使用Firefox扩展(我没有使用JetPack,我不知道它是否可以处理这个)。 Firefox扩展可以与任意XPCOM组件通信。因此,扩展将有一个小的JavaScript部分从DOM中吸取数据,然后与C(++)XPCOM组件进行通信以执行其他任何操作。
See Creating a C++ XPCOM component and Creating Custom Firefox Extensions with the Mozilla Build System
请参阅使用Mozilla Build System创建C ++ XPCOM组件和创建自定义Firefox扩展
#3
Actually, I just realized that the Monkeybread plugin for REALbasic offers all that I need, and in a clearly much easier way than it could be with Jetpack, even:
实际上,我刚刚意识到REALbasic的Monkeybread插件提供了我所需要的一切,并且使用Jetpack的方式明显更简单,甚至:
http://www.monkeybreadsoftware.de/pluginhelp/example-cocoa-domformfields.shtml
I can thus write my own Browser that fetches the webpages and then filters out the DOM data, even modifies it.
因此,我可以编写自己的浏览器来获取网页,然后过滤掉DOM数据,甚至修改它。
#1
This sounds like it could be pretty easy using Jetpack in Firefox.
这听起来在Firefox中使用Jetpack非常容易。
You can create browser extensions using Javascript - it's still in alpha but looks to be workable (and awesome)...
您可以使用Javascript创建浏览器扩展 - 它仍处于alpha状态但看起来可行(并且非常棒)......
#2
I agree you could definitely do this with a Firefox extension (I haven't used JetPack, and I don't know if it could handle this). Firefox extensions can communicate with arbitrary XPCOM components. So the extension would have a small JavaScript part to suck the data out of the DOM, then communicate with a C(++) XPCOM component to do anything else.
我同意你肯定可以使用Firefox扩展(我没有使用JetPack,我不知道它是否可以处理这个)。 Firefox扩展可以与任意XPCOM组件通信。因此,扩展将有一个小的JavaScript部分从DOM中吸取数据,然后与C(++)XPCOM组件进行通信以执行其他任何操作。
See Creating a C++ XPCOM component and Creating Custom Firefox Extensions with the Mozilla Build System
请参阅使用Mozilla Build System创建C ++ XPCOM组件和创建自定义Firefox扩展
#3
Actually, I just realized that the Monkeybread plugin for REALbasic offers all that I need, and in a clearly much easier way than it could be with Jetpack, even:
实际上,我刚刚意识到REALbasic的Monkeybread插件提供了我所需要的一切,并且使用Jetpack的方式明显更简单,甚至:
http://www.monkeybreadsoftware.de/pluginhelp/example-cocoa-domformfields.shtml
I can thus write my own Browser that fetches the webpages and then filters out the DOM data, even modifies it.
因此,我可以编写自己的浏览器来获取网页,然后过滤掉DOM数据,甚至修改它。