Skip to content

Instantly share code, notes, and snippets.

@clonn
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clonn/9541047 to your computer and use it in GitHub Desktop.
Save clonn/9541047 to your computer and use it in GitHub Desktop.
android parse web page - jsoup. use in intelliJ IDE, 用來抓網頁使用,主要處理 query URL, DOM parsing.

#android parse web page - jsoup. use in intelliJ IDE

now you can parse web page like jQUery, "jsoup".

##install jsoup,

Download jsoup jar, and import to your project. save jsoup.jar in libs folder in your project.

open intelliJ.

  • project, right click -> module
  • add, select "jar or directories"
  • import from libs folder jars.

##usage

Before start coding, edit AndroidManifest.xml, enable internet permission. insert line before Application tag.

<uses-permission android:name="android.permission.INTERNET" />

##code

when we want to access web page by URL, have to use thread to process this task, so i use AsyncTask for query web page.

    class testAsynch extends AsyncTask
    {
        protected String doInBackground(Void...arg0) {
            Log.d("DoINBackGround","On doInBackground...");


            try {
                Document doc = Jsoup.connect("http://jsoup.org").get();
                Log.d("info", doc.title());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return "You are at PostExecute";
        }
    }

execute in your activity.java,

	new testAsynch().execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment