Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7735543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:31:43+00:00 2026-06-01T07:31:43+00:00

My code i use to parse HTMl is this below, and the 2nd code

  • 0

My code i use to parse HTMl is this below, and the 2nd code is how i call on it to populate an array for a simplelist.

The problem i have is it take upwards of 5 or 6 seconds to download, parse and display the data, which is far too long.

What is a way to speed up the process so its as close so instant as possible

Also, just so its clear i hard coded the url into the 2nd bit of code, once done, that will be passed in, depending on waht route, direction and stop you use.

public ArrayList<String> getStops(String URL) {
    ArrayList<String> BusStop = new ArrayList<String>();
    String HTML = DownloadText(URL);
    String temp = null;
    String temp2[] = new String[40];
    Pattern p = Pattern.compile("<a class=\"ada\".*</a>", Pattern.DOTALL);

    Matcher m = p.matcher(HTML);
    while (m.find()) {
        temp = m.group();
        temp2 = temp.split("<br></td>");
    }

    for (int i = 0; i < temp2.length; i++) {
        temp = temp2[i];
        temp = temp.replaceAll("<a class=\"ada\" title=\"", "");
        temp = temp.replaceAll("\".*\"", "");
        temp = temp.replaceAll("\n", "");
        temp = temp.replaceAll("\t", "");
        temp = temp.replaceAll(",</a>", "");
        temp = temp.replaceAll("</tr>.*>", "");
        temp = temp.replaceAll("<td.*>", "");
        temp = temp.replaceAll(">.*", "");
        BusStop.add(temp);
    }

    return BusStop;
}

..

TransitXMLExtractor extractor;
static String baseURL5 = "http://www.ltconline.ca/webwatch/ada.aspx?r=1&d=2";

/** Populates string array with bus routes */
public String[] busStopArray() {
    extractor = new TransitXMLExtractor();
    String[] busStopArray = new String[31];

    for (int n = 0; n < busStopArray.length; n++) {
        busStopArray[n] = extractor.getStops(baseURL5).get(n);
    }
    return busStopArray;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:31:44+00:00Added an answer on June 1, 2026 at 7:31 am

    It seems like you could speed things up by pulling the exact text you want with the regular expression and reducing the parsing loop.

    public ArrayList<String> getStops(String URL) {
        ArrayList<String> BusStop = new ArrayList<String>();
        String HTML = DownloadText(URL);
        Pattern p = Pattern.compile("<a class=\"ada\" title=\"([\\w\\s]+)\"");
    
        Matcher m = p.matcher(HTML);
        while (m.find()) {
            BusStop.add(m.group(1));
        }
    
        return BusStop;
    }
    

    Also, the calling bit could just be:

    public String[] busStopArray() {
        extractor = new TransitXMLExtractor();
    
        return extractor.getStops(baseURL5).toArray(new String[0]);
    }
    

    The way I have it now, it should pull the text in the title attribute from each link of class ‘ada’.

    EDIT: To be clear, it should actually pull the the <a class="ada" title="(whatever)", one at a time with the group(1) getting the (whatever) text for you.

    EDIT 2: I updated the examples to match what I found to be working code. Also, here is the entire Activity I used to test with:

    package com.kiswa.test;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.UnsupportedEncodingException;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    
    public class TestActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            StringBuilder sb = new StringBuilder();
            for (String stop : busStopArray()) {
                sb.append(stop);
            }
            Log.d("STRING_TEST", sb.toString());
    
            setContentView(R.layout.main);
        }
    
        public String DownloadText() throws UnsupportedEncodingException, IOException {
            Log.d("STRING_TEST", "In DownloadText");
            URL url = new URL("http://www.ltconline.ca/webwatch/ada.aspx?r=1&d=2");
            BufferedReader reader = null;
            StringBuilder builder = new StringBuilder();
            try {
                reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
                for (String line; (line = reader.readLine()) != null;) {
                    builder.append(line.trim());
                }
            } finally {
                if (reader != null) try { reader.close(); } catch (IOException logOrIgnore) {}
            }
    
            return builder.toString();
        }
    
        public ArrayList<String> getStops() {
            Log.d("STRING_TEST", "In getStops");
            ArrayList<String> BusStop = new ArrayList<String>();
            String HTML = "";
            try {
                HTML = DownloadText();
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Pattern p = Pattern.compile("<a class=\"ada\" title=\"([\\w\\s]+)\"");
    
            Matcher m = p.matcher(HTML);
            while (m.find()) {
                BusStop.add(m.group(1));
            }
    
            return BusStop;
        }
    
        public String[] busStopArray() {
            Log.d("STRING_TEST", "In busStopArray");
            return getStops().toArray(new String[0]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have date formatted in this way: 2010-02-04T00:00:00 I use this code to parse
I use this bit of code to feed some data i have parsed from
I have a HTML code which looks like this. <html><head><meta http-equiv=refresh content=0;url=http://www.abc.com/event/></head></html> I want
I have the following code: use strict; function isDefined(variable) { return (typeof (window[variable]) ===
I have the following test code use Data::Dumper; my $hash = { foo =>
I have an ajax call as below: $.ajax({ type: GET, url: process.php, data: dataString,
I have been tweaking with below sample code. The documentation for MathJax isn't very
I'm trying to parse this HTML block: <div class=v120WrapperInner><a href=/redirect?q=http%3A%2F%2Fwww.google.com%2Faclk%3Fsa%3DL%26ai%3DCKJh--O7tSsCVIKeyoQTwiYmRA5SnrIsB1szYhg2d2J_EAhABIJ7rxQ4oA1CLk676B2DJntmGyKOQGcgBAaoEFk_Qyu5ipY7edN5ETLuchKUCHbY4SA#0%26num%3D1%26sig%3DAGiWqtwtAf8NslosN7AuHb7qC7RviHVg7A%26q%3Dhttp%3A%2F%2Fwww.youtube.com%2Fwatch%253Fv%253D91sYT_8CN8Q%2526feature%253Dpyv%2526ad%253D3409309746%2526kw%253Dsusan%25252#0boyle&amp;adtype=pyv&amp;event=ad&amp;usg=bR7ErKA_3szWtQMGe2lt1dpxzHc= title=The Valley Downs Chicago><img
I have a JavaScript function that I use to call the Facebook API and
I've to read and parse HTML file and populate a data structure (in C++).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.