android - How to scrape HTML and put into TextView? -
i'm trying scrape html , display in textview on press of button calculator-esque app i'm making video game. supposed pull price of item url specified keep getting errors, , i've been stuck @ ages no luck, appreciated, thank you!
package com.elyrs.webscrape; import java.io.ioexception; import java.io.inputstream; import org.jsoup.jsoup; import org.jsoup.nodes.document; import org.jsoup.select.elements; import android.graphics.bitmapfactory; import android.os.asynctask; import android.os.bundle; import android.app.activity; import android.app.progressdialog; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.textview; import android.widget.toast; public class mainactivity extends activity { // url address string url = "http://runescape.wikia.com/wiki/plank"; progressdialog mprogressdialog; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // locate buttons in activity_main.xml button plank = (button) findviewbyid(r.id.plank); // capture button click plank.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // execute title asynctask new plank().execute(); } }); } // title asynctask private class plank extends asynctask<void, void, void> { @override protected void doinbackground(void... params) { try { // connect web site document document = jsoup.connect(url).get(); // html document title elements price1 = document.select("span[class={infobox_quantity}"); // locate content attribute string val1 = price1.attr("data_val_each"); } catch (ioexception e) { e.printstacktrace(); } return null; } @override protected void onpostexecute(void result) { // set downloaded image imageview textview txtdesc = (textview) findviewbyid(r.id.space); txtdesc.settext(val1); mprogressdialog.dismiss(); } } }
Comments
Post a Comment