There is such a line
<div class="emet_index" data-placeholder="current">138,05</div> How to find and display numbers from this line? in any way. Of course the best is not difficult. This line is not repeated.
138,05How to find and ...">
If you take this line from HTML, then JSOUP (or another parser) will help you. Find the desired item and take its contents using the text() method
And do not get fooled by the advice of those who suggest using regular expressions to solve this problem.
Updated
Example:
import org.jsoup.Jsoup; import org.jsoup.nodes.*; class Test { public static void main(String[] args) throws Exception { // Загружаем в парсер страницу с указанного URL (есть методы, // которыми можно взять страницу из переменной или файла) Document doc = Jsoup.connect("http://site.ru/page").get(); // Выбираем нужные элементы согласно CSS-селектору (".emet_index"), // берем их текст и выводим в консоль System.out.print(doc.select(".emet_index").text()); } } JSOUP API is very similar to jQuery
select() method, the argument of which is the CSS selector, then the text content is taken from the element. - tutankhamunAs option through simple SubString
String myStr = "<div class=\"emet_index\" data-placeholder=\"current\">138,05</div>"; String sec = myStr.substring(myStr.indexOf(">") + 1, myStr.indexOf("</")); System.out.println(sec); I would use replaceAll and a regular expression
String s = "<div class=\"emet_index\" data-placeholder=\"current\">138,05</div>"; String str = s.replaceAll("[^0-9]", ""); If you need a comma - it is also not difficult to modify.
Source: https://ru.stackoverflow.com/questions/471571/
All Articles
divtag? Need a string (String) or a number (double)? - user194374