I am parsing content using the following code with jsoup.
try{
Elements divElements = jsDoc.getElementsByTag("div");
for(Element divElement : divElements){
if(divElement.attr("class").equals("article-content")){
textList.add(divElement.text());
text = textList.toString();
}
}
}
catch(Exception e){
System.out.println("Couldnt get content");
}
The only problem is the content is returned with brackets around it [] like that.
Im guessing it is becaue of the list i am setting it to. How can i remove these?
Brackets can be removed from a string in Javascript by using a regular expression in combination with the . replace() method.
Using regex to replace the leading and trailing brackets, String.replace() doesn't work for the edge cases that the list's content contains brackets.
String text = textList.toString().replaceAll("(^\\[|\\]$)", "");
Replace:
text = textList.toString();
with:
text = textList.toString().replace("[", "").replace("]", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With