2014年3月27日 星期四

android parse web page - jsoup. use in intelliJ IDE

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();

沒有留言:

張貼留言

Facebook