私はHTMlを解析するために私のコードを使用しています.2番目のコードは単純リストの配列に値を設定する方法です。データを解析して配列を取り込む方法
私が持っている問題は、あまりにも長いデータをダウンロードし、解析して表示するには5〜6秒かかることです。
その明確な私はハード渡されます一度行われたコードの2ビット目にURLを、コード化されたばかりので、また
できるだけそうインスタントその限り近づけてプロセスをスピードアップするための方法は何ですかあなたが使用するルートと方向に応じて、停止します。
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;
}
まず、私は最も時間のかかる手順を見つけようとします。これは単純にネットワーキングのステップになる可能性があり、この場合、スピードアップはほとんど不可能です。 –
別の考え方 - サーバーがJSONまたはXML(現在のHTMLと比較して)でデータを返すようにサーバーを制御する場合、デバイス側ではデータをより高速に解析することができます。 –
トランジットアプリケーションを作成する予定の場合、iRailチームに連絡することをお勧めします。http://project.irail.be/彼らは、輸送会社、サーバー、NPOなどのデータを掻き集めるツールがたくさんあります、すべてがopensourceです! –