简体   繁体   English

Java Runtime exec:从Firefox获取信息

[英]Java Runtime exec: Get information from Firefox

With Java I am able to open Firefox just fine with a URL I set using this code: 使用Java,我可以使用使用以下代码设置的URL打开Firefox:

Runtime.getRuntime().exec("C:\\Program Files\\Mozilla Firefox\\firefox.exe" + " " + "http://www.website.com");

But if possible how can I then return the following data? 但是,如果可能的话,我该如何返回以下数据?

  1. If Firefox loaded successfully? Firefox是否成功加载? (As a bool) (作为布尔)
  2. If the URL(s) loaded successfully? URL是否成功加载? (As a bool, or if using more than 1 URL as a bool array) (作为布尔值,或者如果使用多个URL作为布尔值数组)
  3. The time taken to load (As a value/string, or if using more than 1 URL as a value/string array. 加载所需的时间(作为值/字符串,或者如果使用多个URL作为值/字符串数组。
  4. The contents of the Firefox Web Console (As a string, or if using more than 1 URL as a string array) Firefox Web控制台的内容(作为字符串,或者如果使用多个URL作为字符串数组)

Is there a way to do this and get back this type of data from Firefox or other programs that .exec is launching? 有没有办法从Firefox或.exec启动的其他程序中获取此类数据?

You're simply not going to get very much mileage from Java Runtime.exec(), IMHO... 您根本不会从Java Runtime.exec(),恕我直言中获得很多帮助...

Here's an alternative that should let you do some/most of what you're trying to do ... from Perl (not Java): 这是一种替代方法,应该使您可以从Perl(而不是Java)中执行您要执行的部分/大部分操作:

That's just an example. 这只是一个例子。 There are many, many other alternatives. 还有许多其他选择。 If you want to go the Java route, search for "screen scrapers" or "automation". 如果要使用Java,请搜索“屏幕抓取器”或“自动化”。 For example: 例如:

'Hope that helps 希望有帮助

I would recommend to take a look at Selenium... Basically, you need (of course) a monitor for the firefox process, and since Firefox does not offer COM you need sth "inside" firefox, ie a plugin. 我建议看一下Selenium ...基本上,您(当然)需要一个用于firefox进程的监视器,并且由于Firefox不提供COM,因此您需要使用“内置” firefox(即插件)。 This is what selenium does. 这就是硒的作用。 Such a plugin then could send you any internals for instance through a simple tcp connection. 这样的插件随后可以通过简单的tcp连接向您发送任何内部信息。

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

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