1

There is my html input:

  <!-- left panel --> 
  <div class="left-panel"> 
    <p class="article-published"> 1. júl 2015 o 17:35 &nbsp;&nbsp; Marek Hudec, Dávid Tvrdoň </p>
  </div>

and the code:

if(doc.select("p[class=article-published]").isEmpty() == FALSE){
    Elements description = doc.select("p[class=article-published]");
    for (Element link : description) {
        author4 = link.text();
    }
    System.out.println("AUTHORS :" + author4);
 }

I would like to get the output, like: Marek Hudec, Dávid Tvrdoň. So only the name of those guys. But yet I can not got it. Someone help me please. Thank you

4
  • JSoup can only get you the contents between the tag, which you've already done. Figuring out what is a name and what is a date isn't a problem for JSoup. If the format you presented is consistent, then you could skip over the initial date and time (you know what a date and time will look like, so you find it and print the stuff after it).
    – pushkin
    Oct 28, 2015 at 18:01
  • I should verify though, are you getting the right contents in the first place (the date, time, plus authors) or something else entirely?
    – pushkin
    Oct 28, 2015 at 18:02
  • The problem is that, I dont get nothing... only empty output with the code above. Oct 28, 2015 at 19:04
  • Ahh, but it still compiles? FALSE should be false, unless you are defining some constant FALSE above.
    – pushkin
    Oct 28, 2015 at 20:25

1 Answer 1

0

All you have to do is to parse the Text you get from Jsoup and chop the data you want from it, in below code i modified your code to get the data from specific index.

 import java.util.Arrays;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;

 public class KolosParsor {   
        public static void main(String[] args) {
            String author4 = null;
            Document doc = Jsoup.parse("<div class=\"left-panel\">"+ 
             "<p class=\"article-published\"> 1. júl 2015 o 17:35 &nbsp;&nbsp; Marek Hudec,Dávid Tvrdoň </p>");
            if(!doc.select("p[class=article-published]").isEmpty()){
                Elements description = doc.select("p[class=article-published]");
                for (Element link : description) {
                     author4 = link.text();
                 }
                 System.out.println("DATA :" + Arrays.asList(author4.split(" ")));
                 System.out.println("AUTHORS :" + Arrays.asList(author4.split(" ")).get(7));
             }          
        }
    }
4
  • But I need, to parse not only this example, but there are lot... this is only one of them. So I need one universal code for doing this step. Oct 28, 2015 at 19:01
  • this is just an example for one kinda parsing, webpages / html is so diffrent in universe you cant write universal code for it, though i would recommend to look at apache nutch+apache tika for your requirement. Oct 28, 2015 at 19:15
  • The structure of the other html`s are like this one... only difference is date and the autors name. But div class and p class are equal to this one. Oct 28, 2015 at 19:21
  • thats where this code will help you ... just put it in a loop, think little bit how you can how you can do same process again n again in loop Oct 28, 2015 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.