[英]How can I implement similar to the web query feature in Excel in java?
I'm new here and I hope I'm not asking something which has already been answered. 我是新来的,希望我不要问已经回答的问题。 I have searched everywhere but am yet to discover an adequate answer.
我到处搜索过,但尚未找到适当的答案。
My objective is fairly simple: I want to create a program which will stream the live gold and silver rates from: this website 我的目标非常简单:我想创建一个程序,该程序将流转来自以下网站的实时黄金和白银汇率:
How would I be able to pinpoint the values that I want to download? 如何确定要下载的值? Currently, I have managed to implement this using Microsoft Excel's web query feature wherein I am able to select a table from the webpage.
目前,我已经设法使用Microsoft Excel的网络查询功能来实现此目的,其中我可以从网页中选择一个表格。 However, I want to make it a standalone application.
但是,我想使其成为一个独立的应用程序。
By the way, I need to retrieve the rates to perform a calculation which is then displayed to the user. 顺便说一句,我需要检索比率以执行计算,然后将其显示给用户。
I would greatly appreciate any ideas on how this can be achieved. 我将不胜感激关于如何实现这一目标的任何想法。
I think you need to scrape
or parse
the data from your website. 我认为您需要从网站上
scrape
或parse
数据。 For that take a look at htmlcleaner , JSoup html parsers. 为此,请看htmlcleaner , JSoup html解析器。
You can use XPath
with htmlcleaner to pinpoint the data.Here is a nice example Xpath Example . 您可以将
XPath
与htmlcleaner一起使用来查明数据。这里是一个很好的Xpath Example示例 。
You can use firefox's firebug
extension to get the xpath of an element. 您可以使用firefox的
firebug
扩展来获取元素的xpath。 But your xpath is going to be very huge, by the look of the website you mentioned. 但是从您提到的网站来看,您的xpath将会非常庞大。
Than you have to execute the code at specified interval of your choice. 比起您必须按选择的指定间隔执行代码。
And if there is javascript
in play than you have to execute the javascript running behind the page using your java code. 而且,如果正在播放
javascript
,则必须使用Java代码执行在页面后面运行的javascript。
Try using Rhino
from Mozilla and using its integration libraries or by using the JDK 1.6 ScriptEngine
facility. 尝试使用Mozilla中的
Rhino
并使用其集成库或使用JDK 1.6 ScriptEngine
工具。
For ScriptEngine
Example take a look here- http://metoojava.wordpress.com/2010/06/20/execute-javascript-from-java/ 对于
ScriptEngine
实例来看看这里- http://metoojava.wordpress.com/2010/06/20/execute-javascript-from-java/
In, short take a look at
html parsers
to parse the content of your page.在其中,简短介绍一下
html parsers
以解析页面的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.