我正在使用以下代码使用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");
}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是内容返回括号围绕它[]那样.
我猜这是因为我正在设置它的列表.我怎样才能删除这些?
Eng*_*uad 27
更换:
text = textList.toString();
Run Code Online (Sandbox Code Playgroud)
有:
text = textList.toString().replace("[", "").replace("]", "");
Run Code Online (Sandbox Code Playgroud)
使用正则表达式替换前括号和后括号,String.replace()不适用于列表内容包含括号的极端情况。
String text = textList.toString().replaceAll("(^\\[|\\]$)", "");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22419 次 |
| 最近记录: |