我不确定如何解析" bundesweit"和jsoup中的日期字符串,因为它们都是相同的类名(col2)
<strong><a href="/stellenangebote/109499-python-entwickler-gui-testing?page=1&query%5Bcity%5D=&query%5Bradius%5D=100&query%5Btext%5D=Python" title="Python-Entwickler (m/w) GUI Testing">Python-Entwickler (m/w) GUI Testing</a></strong>
<br>
<a class="job-offer-teaser-company" href="/unternehmen/ruecker-gmbh" title="Rücker">Rücker</a>
</div>
<div class='col2'>
bundesweit
</div>
<div class='col2'>
08.12.2013
</div>
我试过了:
Elements jobTitleElement = element.select("a");
Elements companyNameElement = element.select(".job-offer-teaser-company");
Elements locationElement = element.select(".cal2");
非常感谢
答案 0 :(得分:1)
如果HTML遵循相同的结构,只需选择它们,然后使用索引将它们拆分。
//Get the HTML
Document doc = Jsoup.parse(html);
//or
Document doc = Jsoup.connect(url).get();
//Select the elements
Elements col2Elements = doc.select("div.col2"); //This will return a collection of Element objects
String firstElement = col2Elements.get(0).text(); //Get the first
String secondElement = col2Elements.get(1).text(); //Get the second
答案 1 :(得分:1)
您可以使用以下代码:
Document doc = Jsoup.parse(html);
Elements elements = doc.getElementsByClass("col2");
String bundesweitContent = elements.get(0).text();
System.out.println(bundesweitContent); // You get "bundesweit"
参考: