【发布时间】:2017-10-15 19:52:40
【问题描述】:
我得到了一个像这样的 Arraylist
[netl, entl, ltc, 6.3, 6.3, maat, lo, CombiGym, mr, wisB, nat, schk, biol, 6.4, 6.4, wisD, L&W, 9, 8.5, reken, exp]
我希望它看起来像这样
[netl, entl, ltc 6.3 6.3, maat, lo, CombiGym, mr, wisB, nat, schk, biol 6.4 6.4, wisD, L&W 9 8.5, reken, exp]
我不希望数字成为 ArrayList 中的单独对象。 这是我的代码
ArrayList<String> arrayvakken = new ArrayList<String>();
String loginFormUrl = "https://example.com/login?path=%2F%3F";
String loginActionUrl = "https://example.com/login?passAction=login&path=%2F%3F";
String username = "USERNAME";
String password = "PASSWORD";
HashMap<String, String> cookies = new HashMap<>();
HashMap<String, String> formData = new HashMap<>();
Connection.Response loginForm = Jsoup.connect(loginFormUrl).method(Connection.Method.GET).userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0").execute();
Document loginDoc = loginForm.parse(); // this is the document that contains response html
cookies.putAll(loginForm.cookies()); // save the cookies, this will be passed on to next request
formData.put("Login", "Inloggen");
formData.put("wu_loginname", username);
formData.put("wu_password", password);
Connection.Response homePage = Jsoup.connect(loginActionUrl)
.cookies(cookies)
.data(formData)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0")
.method(Connection.Method.POST)
.execute();
Document document2 = Jsoup.connect("https://example.com/Portaal/Cijfer_menu/Cijferoverzicht").cookies(cookies).get();
for(Element element : document2.select(".vak,.wp3-cijfer")) {
arrayvakken.add(element.select(".vak,.wp3-cijfer").text());
}
for(String str : arrayvakken) {
Pattern p = Pattern.compile("([0-9])");
Matcher m = p.matcher(str);
if(m.find()){
System.out.println("number");
} else {
System.out.println("word");
}
}
}
我将如何格式化顶部所示的 ArrayList?
【问题讨论】:
-
该代码与这些数组有什么关系?
-
列表中的类型是什么??
-
String,我正在使用Jsoup从网站获取数据