0

Iwould like to extract a lectureinfo room in the div tag, however I tried to to get the lecture room by using (div.lectureinfo room) but it brings me other stuff in the table. can someone help me? this is the source code.

<tr class="odd">
    <th>9:00</th>
        <td>
            <div class=slot data-hour="9" data-day="0" data-day-of-month="9" data-month-name="June" data-month="6" data-year="2014"><span class=target></span>
                    <div rel=tipsy title="Lecture" class="lecture " data-lecture-pk="21044">
                            <strong>CS-M71</strong>
                            <span>CJW</span>
                            <div class="lectureinfo room">Faraday 205 Robert Recorde</div>
                                <div class="lectureinfo weeks">Weeks: 15-16, 18-25</div>
                    </div>
Filburt
  • 17,626
  • 12
  • 64
  • 115
user3274585
  • 21
  • 1
  • 4

1 Answers1

0

First of all, there are a tremendous amount of questions on StackOverflow and over the internet where how to do this is described. The best source would still of course be the Jsoup documentation, and especially the Jsoup cookbook.

To select an element with multiple classes, such as the <div class="lectureinfo room"> you'll have to separate the classnames with a ., such as

Document doc = Jsoup.parse(html);
Element lectureRoom = doc.select("div.lectureinfo.room").first();
System.out.println(lectureRoom.text());

which will output

Faraday 205 Robert Recorde

Make sure to look through the cookbook extensively to get as much out of Jsoup as possible!

Daniel B
  • 8,770
  • 5
  • 43
  • 76
  • Thanx I get it now. the other things Iwould like to fix it is I have about 20 lecture room and I would like to desplay it using new line, at the moment they all on one line?? – user3274585 Jul 24 '14 at 22:04
  • That is another question and an easy one for you to look up. It's programmatically non related to this question, and if the Jsoup code I supplied worked you should mark it as an answer. Regarding a new line for each classroom, look at this [Printing in new line - Java](http://stackoverflow.com/questions/4008223/print-in-new-line-java) – Daniel B Jul 25 '14 at 06:50
  • I have looked at the printing in new line as you said but it doesn't work with me. For example I have this code: – user3274585 Jul 25 '14 at 10:03
  • Elements Troom = table.select("div.lectureinfo.room"); the output is : Faraday 205 Robert Recorde Glyndwr A Faraday 205 Robert Recorde Faraday Rm J Faraday 205 Robert Recorde Glyndwr A Grove Seminar Rm 4 (Rm 324A) Faraday 205 Robert Recorde Faraday 314 Board Room Grove Project Lab Faraday 314 Board Room Faraday 205 Robert Recorde Glyndwr Rm E Talbot 224 Faraday 205 Robert Recorde Grove Project Lab Faraday 504 Faraday 205 Robert Recorde , all the lecture room but all in one line. Iam using netbeans and Iam new programmer. – user3274585 Jul 25 '14 at 10:06
  • `Elements` get all the elements, so of course it will get all the lecture rooms. Loop through the `Elements` collection and print each `Element` once and you'll have separate lines. Please, read the documentation! This is basics! – Daniel B Jul 25 '14 at 10:26