ZedBrannigan
ZedBrannigan

Reputation: 611

How to parse this specific Data in Jsoup

im not sure how to parse the "bundesweit" and the date string in jsoup, since its both the same class name (col2)

<strong><a href="/stellenangebote/109499-python-entwickler-gui-testing?page=1&amp;query%5Bcity%5D=&amp;query%5Bradius%5D=100&amp;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>

I tried this:

Elements jobTitleElement = element.select("a");
                        Elements companyNameElement = element.select(".job-offer-teaser-company");
                        Elements locationElement = element.select(".cal2");

Thank you very much

Upvotes: 0

Views: 76

Answers (2)

Daniel B
Daniel B

Reputation: 8879

If the HTML follows the same structure, just select them both and then split them up using indexing.

//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

Upvotes: 1

Guo Song
Guo Song

Reputation: 352

You can use the following codes:

Document doc = Jsoup.parse(html);
Elements elements = doc.getElementsByClass("col2");
String bundesweitContent = elements.get(0).text();
System.out.println(bundesweitContent); // You get "bundesweit"

reference:

http://jsoup.org/cookbook/introduction/parsing-a-document

http://jsoup.org/apidocs/

Upvotes: 1

Related Questions