Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: parse html from page

Tags:

android

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

like image 929
Johan Avatar asked Jan 14 '11 14:01

Johan


People also ask

How to parse HTML data in Android?

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.

How to parse HTML response in Android?

parse(responseString); String nameL = doc. select("input[name=nameL]"). attr("value"); String level = doc. select("input[name=level]").

Does Jsoup work on Android?

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.

What is Jsoup Android?

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.


1 Answers

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

like image 132
Computerish Avatar answered Oct 27 '22 23:10

Computerish