Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsoup Import Errors

Tags:

java

import

jsoup

I'm looking to do some web crawling/scraping and I did some research and discovered Jsoup. The only problem I'm having is with the imports. The videos I've watched and examples I've seen have all had matching code to mine but for whatever reason their imports worked and mine don't. All four of mine give the error: The import org.jsoup cannot be resolved. Please help.

package com.stackoverflow.q2835505;

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

public class test {

public static void main(String[] args) throws Exception {
    String url = "http://stackoverflow.com/questions/2835505";
    Document document = Jsoup.connect(url).get();

    String question = document.select("#question .post-text").text();
    System.out.println("Question: " + question);

    Elements answerers = document.select("#answers .user-details a");
    for (Element answerer : answerers) {
        System.out.println("Answerer: " + answerer.text());
  }
 }
}
like image 325
mpchenette Avatar asked Sep 09 '15 20:09

mpchenette


People also ask

How install Jsoup in Netbeans?

in netbeans in project window Expand your project and right click on libraries ans select add jar/folder and locate your jsoup. jar and selenium. jar file locations and Add them. Then build the project.

What is Jsoup element?

A HTML element consists of a tag name, attributes, and child nodes (including text nodes and other elements). From an Element, you can extract data, traverse the node graph, and manipulate the HTML.

What is Jsoup library?

Jsoup is a Java html parser. It is a Java library that is used to parse html documents. Jsoup gives programming interface to concentrate and control information from URL or HTML documents. It utilizes DOM, CSS and Jquery-like systems for concentrating and controlling records.


1 Answers

jsoup is a external library and therefore you need to download the jar manually. Go to http://java2s.com/Code/Jar/j/Downloadjsoup160jar.htm or some website and get the jar file.

Once you download the jar file. Right click on your project -> Properties -> Java Build Path -> Click on Add External Jar -> (select the jar where you downloaded) -> press ok and error will go away.

like image 183
logger Avatar answered Oct 20 '22 03:10

logger