################ REPORT ###################
Setup
Item1 1120Item2 Copy free
Item3 8/3/2017 5:44:51 AM
Item4
我需要阅读的信息与
线。我们的目标是将这些信息保存到一个Excel文件像下面
我目前使用的BufferedReader阅读HTML文件,但我不知道如何来分隔行包含字段和值。我试图使用散列表来保存它的字段名称和值,但我不能以正确的方式获取值。我也试过Jsoup摆脱HTML标签的,但它给了我更多的复杂性读取线以来,HTML文件
private final String[] modStrings = new String[]{"Item1", "Item2", "Item3", "Item4", "Item5"};
public void readHtmlFile() throws IOException {
FileReader reader = new FileReader("C:\\Users\\file.html");
// StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(reader);
String line;
String[] tempContent = {};
ArrayList content = new ArrayList();
HashMap modMap = new HashMap<>();
while ((line=br.readLine()) != null) {
tempContent = line.split("
");
for(int i = 0; i < tempContent.length; i++){
for (String sub:modStrings){
if(tempContent[i].contains(sub)){
String value = "TODO HERE"; // TODO
content.add(sub);
modMap.put(sub, value);
}
}
}
}
// String textOnly = Jsoup.parse(sb.toString()).text();
for(int i = 0; i < content.size(); i++){
System.out.println(content.get(i));
System.out.println(modMap);
}
}
任何建议或想法将是一个很大的帮助。
2017-08-04
Minwu Yu
+0
通过上面的HTML结构,用'分裂(“< br“)不是给你想要的。你应该使用''split'与'space'来获得'Item'并且值 –
+0
你可以使用String [] keyVal = s.trim()。split(“+”); value = keyVal [1]; key = keyVal [0); –
+0
@TuyenNguyen,我不能使用split(“”),因为有时候这个值还包含一个空格,如果我用空格拆分,它也会拆分我想要的值。 (例如,免费复制和8/3/2017 5:44:51 AM) –