You can use the jsoup library for this. Example: To get all spans from google , you could do this:
Document doc = Jsoup.connect("https://www.google.com.br").get();
doc.select("span")
.stream()
.forEach(s -> System.out.println(s.text()));
Edit :
To search for an element that contains a given text, you can use the Pseudo-selectors :containsOwn(textoASerBuscado)
or :matchesOwn(regex)
. Example:
Document doc = Jsoup.connect("https://www.google.com.br").get();
doc.select("span:containsOwn(google)") //Busca todos os spans que contenham "google"
.stream()
.forEach(s -> System.out.println(s.text()));
To find out about other selectors, you can look in the Selector class documentation