I want to get the html contents from a website
and I use the jsoup(java open source ) ,to crwal a web site and get the elements with this code:
Document doc = Jsoup.connect("http://bj.58.com/shangdi/zufang/0/").get();
Elements hrefs = doc.select("*");
Elements hrefs2 = hrefs.select("td:lt(4)");
System.out.println(hrefs2);
and i get the result:
<td class="tc"><b class="pri">2100</b></td>
<td class="tc">ABCD</td>
<td class="tc">today</td>
or I edit this code(just add a “text()”in the last line ) :
Elements hrefs2 = hrefs.select("td:lt(4)");
System.out.println(hrefs2.text());
and i get the result:
2100 ABCD today
but I really want to acheive is like this result:
2100,ABCD,today
is any way to add the comma into the result,so that easy to save the result into the database with csv file.
You can get an iterator over the resultant
Elementsfromhrefs.select, and at that point you can do whatever you want with the list (i.e., format it however you wish).