简体   繁体   English

Java-在网站上查找特定数字

[英]Java - Finding a certain number on a website

What would the method be to find a number after a String of text 在文本字符串后查找数字的方法是什么

Example would be the latest version of something. 示例是某事的最新版本。

So basically it would open up a URL, use the BufferedReader and search for a String of text. 因此,基本上,它将打开一个URL,使用BufferedReader并搜索文本字符串。 The number (int / double) would be found after the String and the program would compare the latest version with the current version. 在字符串之后可以找到数字(int / double),程序会将最新版本与当前版本进行比较。

Thanks in Advance 提前致谢

Using an HTML parser like @qrtt suggested is a good idea. 建议使用类似@qrtt这样的HTML解析器是一个好主意。 But you could also do the following. 但是您也可以执行以下操作。 Take the entire response from the page, and use regex to find your string 从页面中获取整个响应,然后使用正则表达式查找您的字符串

The regex would be something like /string_of_text=[0-9]*/g That would return the string of text along with the number after it, which you can use, with a little string manipulation. 正则表达式将类似于/string_of_text=[0-9]*/g ,它将通过一些小的字符串操作返回文本字符串以及其后的数字,您可以使用它。

You need a parser like Jsoup to parse your content into tokens. 您需要一个像Jsoup这样的解析器来将您的内容解析为令牌。 Then run a search using regex. 然后使用正则表达式运行搜索。 I'm not too good with regex so maybe you can use txt2re.com for this. 我对正则表达式不太满意,因此也许您可以使用txt2re.com

我找到了一个解决方案,我使用子字符串找到了“版本= X”所在的位置,然后将其解析为double

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

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