Parse HTML response in android and get data from specific tag,id,class throw

Hear is the example which explain how to parse html tag in android.

For HTML parsing we are using common Jsoup library which help you to parse html data easily.
Click Hear to Get a Library (http://jsoup.org/download)




private void callForSummary(final String stock_symbole) {
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                String url = "https://www.google.com/finance?q=" + stock_symbole;
                Document doc = Jsoup.connect(url).get();
                final Element companySummary = doc.select("div.companySummary").first();
                mProfileActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.d("companySummary----data", companySummary.data());
                        Log.d("companySummary----id", companySummary.id());
                        Log.d("companySummary----text", companySummary.text());
                        mLblSumDesc.setText("" + companySummary.text());
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    thread.start();
}

No comments: