I'm making an android app and I wanna web scrape a page with motorcycles. When I had iterated over the elements of that page they got printed with html tags but since I had put .text() method, I got everything printed in one line on my terminal. You can check my code down below for a better understanding. Thanks in advance.
@Override
protected String doInBackground(Void... voids) {
String title = "";
try {
Document document = Jsoup.connect("https://www.hotcars.com/best-motorcycles-for-beginners/").get();
Elements elements = document.select("div[class=w-website]").select("div[class=w-content]");
for (Element element : elements.select("section[class=article-body]")) {
title = element.select("h2").text();
System.out.print(title);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
If I delete .text() from the title, then I get my text but with html tags which I don't need.