Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Jsoup to my Android Studio project?

I am trying to use jsoup in my android studio project but i keep getting this error: Error:(10, 16) Gradle: error: package org.jsoup does not exist.

Could you guys tell me the steps on how to add jsoup library to my project? Thanks in advance.

Edit: For learning purpuse i am running the java code alone without main activity!

code:

package com.jsoupTest.jsoupTest;


import java.io.IOException;




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

import java.io.IOException;

public class JsoupGetRequest {


    public static void main(String[] args) throws IOException {



        String dc=Jsoup.connect("http://somelink.com").timeout(6000).get();
        System.out.println(dc);
    }

}
like image 642
user1788736 Avatar asked Jul 06 '17 23:07

user1788736


People also ask

What is jsoup Android?

jsoup is a Java library for working with real-world HTML. It provides a very convenient API for fetching URLs and extracting and manipulating data, using the best of HTML5 DOM methods and CSS selectors. jsoup implements the WHATWG HTML5 specification, and parses HTML to the same DOM as modern browsers do.

How do I get jsoup in eclipse?

If you use Eclipse…Right click on the project (ctrl+enter) and select “Java Build Path” from the sidebar and then “Libraries” from the top bar. Finally, choose “Add External JARs…” and import the Jsoup JAR file.

Where is jsoup used?

jsoup can parse HTML files, input streams, URLs, or even strings. It eases data extraction from HTML by offering Document Object Model (DOM) traversal methods and CSS and jQuery-like selectors. jsoup can manipulate the content: the HTML element itself, its attributes, or its text.


2 Answers

Gradle (build.gradle) in your app folder. put under dependencies section. clean and rebuild project

// jsoup HTML parser library @ https://jsoup.org/
implementation 'org.jsoup:jsoup:1.10.3'
like image 106
ZeroOne Avatar answered Oct 17 '22 01:10

ZeroOne


You should add your dependencies in your build.gradle file. Please check the screenshot attached.

build.gradle file location on Android Studio

like image 28
notGeek Avatar answered Oct 17 '22 00:10

notGeek