我正在使用返回列表的 JerichoHTML 解析器(getAllElements 方法)解析 HTML 数据。但是,我需要将数据存储在 String[] 中。但是我是怎么做的,(即使通过像 (String) ((Object) theList) 这样的嵌套转换)它总是失败....知道如何解决这个问题吗?在jericho docs上找不到任何帮助...
public static String[] htmlParser(String htmlText){
Source source = new Source(htmlText);
List<Element> filteredList = source.getAllElements("p");
String[] filteredArray = new String[filteredList.size()];
for(int i = 0; i<filteredList.size();i++){
filteredArray[i] =(String) ((Object) filteredList.get(i));
}
return filteredArray;
}
错误如下:
Exception in thread "main" java.lang.ClassCastException: net.htmlparser.jericho.Element cannot be cast to java.lang.String
at InternalLinking.InputKeywordsLinksAlternative.htmlParser(InputKeywordsLinksAlternative.java:156)
at InternalLinking.InputKeywordsLinksAlternative.inputLinksCountLess150(InputKeywordsLinksAlternative.java:70)
at InternalLinking.InputKeywordsLinksAlternative.applyWordCountFilters(InputKeywordsLinksAlternative.java:61)
at InternalLinking.InputKeywordsLinksAlternative.main(InputKeywordsLinksAlternative.java:21)