Android - Parse text from website

I have webpage with this simple text, which is changeable.

<html><head><style type="text/css"></style></head><body>69766</body></html>

I need parse only number 69766 and save it to variable as String or int. It's possible to parse this number without adding libraries?

Thanks for your questions !

Upvotes: 1

Views: 1395

Answers (3)

Alan
Alan

Reputation: 1549

this link shows how to parse the xml with the SAX parser. Its pretty straight forward. http://www.codeproject.com/Articles/334859/Parsing-XML-in-Android-with-SAX

Upvotes: 0

Arun C
Arun C

Reputation: 9035

You can do like this

    URL url = new URL("http://url for your webpage");
    URLConnection yc = url.openConnection();
    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                            yc.getInputStream()));
    String inputLine;
    StringBuilder builder = new StringBuilder();
    while ((inputLine = in.readLine()) != null) 
        builder.append(inputLine.trim());
    in.close();
    String htmlPage = builder.toString();

    String yourNumber = htmlPage.replaceAll("\\<.*?>","");

Upvotes: 2

r4m
r4m

Reputation: 491

For your basic need you should take a lot at Html class.

Upvotes: 0

Related Questions