i would like to parse out some text from a page.
Is there an easy way to save the product info in to a string for example? Example url: http://upcdata.info/upc/7310870008741
Thanks
This example demonstrates how do I parse HTML in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
parse(responseString); String nameL = doc. select("input[name=nameL]"). attr("value"); String level = doc. select("input[name=level]").
In this case we can use JSoup that has a set of powerful API very easy to use and integrate in our Android projects. In this post we will discuss how to setup and Android project that uses JSoup and how to extract some information.
Jsoup is a Java html parser. It is a Java library that is used to parse html documents. Jsoup gives programming interface to concentrate and control information from URL or HTML documents. It utilizes DOM, CSS and Jquery-like systems for concentrating and controlling records.
Jsoup is excellent at parsing simple HTML from Android applications:
http://jsoup.org/
To get the page, just do this:
URL url = new URL("http://upcdata.info/upc/7310870008741");
Document document = Jsoup.parse(url, 5000);
Then you can parse out whatever you need from the Document
. Check out this link for a brief description of how to extract parts of the page:
http://jsoup.org/cookbook/extracting-data/dom-navigation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With