How to use Jsoup library to get "a" tag from a webpage?


Step 1: Go to: and download core library to your desktop or any location you want. Ctrl + C to make a copy of your .JAR library file.

Step 2: Here i use Android studio, see on the top-left side of android studio, change “android” to “project” explorer view. Browse to the path: /App/libs, right click on “libs” folder and paste the .JAR file we copied before.

Step 3: Right click on your project name in project explorer, open module settings, a new dialog appear. See on the top left and click add button (a green plus icon). choose “import .JAR….blabla”. Next, browse to the jAR file and click finish. Waiting for the gradle is built successfully.

See the code below:

package com.wordpress.davidng.spinner;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

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

import java.lang.reflect.Array;
import java.util.ArrayList;
public class MainActivity extends ActionBarActivity {
private TextView tv;
private Spinner spinner;

ArrayList<String> links = new ArrayList<String>();
ArrayAdapter<String> adapter;
protected void onCreate(Bundle savedInstanceState) {
tv = (TextView) findViewById(;
spinner = (Spinner) findViewById(;

runOnUiThread(new Runnable() {
public void run() {
new readJsoup().execute("");
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
tv.setText("Bạn đã chọn: " + links.get(position));
public void onNothingSelected(AdapterView<?> parent) {

class readJsoup extends AsyncTask<String, Void, Void>{
protected Void doInBackground(String... params) {
try {
Document doc = Jsoup.connect(params[0]).get();
Elements link ="a");
for(Element a : link){
} catch (IOException e) {
return null;
protected void onPostExecute(Void aVoid) {
adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_item, links);


Note: Remember to modify android manifest and add INTERNET permission.