1

I have a java program to parse an html page This is my java program to parse a html page

package com.mkyong;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

 public class HTMLParserExample1 {

 public static void main(String[] args) {

 Document doc;
   try {

     // need http protocol
     doc = Jsoup.connect("http://google.com").get();

     // get page title
     String title = doc.title();
     System.out.println("title : " + title);

     // get all links
     Elements links = doc.select("a[href]");
     for (Element link : links) {

        // get the value from href attribute
        System.out.println("\nlink : " + link.attr("href"));
        System.out.println("text : " + link.text());

       }

     }    catch (IOException e) {
      e.printStackTrace();
      }

     }

    }

But when in run this code using javac name.java , the following errors occur

java.java:7: package org.jsoup.nodes does not exist import org.jsoup.nodes.Element

from the internet, some said to point the path of jar file , I downloaded the jsoup file and i dont know to how to point it or to install it, PLease help me twith the error

Do i need to modify the code or modify the way of compiling

  • 1
    It is true, you need to download JAR which contains classes necessary to use Jsoup. Then you need to let compiler `javac` and runner `java` know where this jar is located. In other words you need to include it in classpath. Are you using any IDE (Eclipse, NetBeans, ...)? – Pshemo Sep 29 '15 at 17:52
  • I downloaded jar , i'm doing this without any IDE, just a simple .java file, I don't know how to or where point the path, do i have to explain it in my code or any other place, please give me a example –  Sep 29 '15 at 18:15
  • Then try compiling and running your code with `-cp` pointing to that jar file like `javac -cp "c:/new folder/jsoup.jar" YourClass.java`. Same with `java` command. – Pshemo Sep 29 '15 at 18:18

0 Answers0