私はページからいくつかのテキストを解析したいと思います。android:parse html from page
たとえば、文字列に商品情報を保存する簡単な方法はありますか? URL例:http://upcdata.info/upc/7310870008741
おかげ
私はページからいくつかのテキストを解析したいと思います。android:parse html from page
たとえば、文字列に商品情報を保存する簡単な方法はありますか? URL例:http://upcdata.info/upc/7310870008741
おかげ
Jsoupは、Androidアプリケーションから簡単なHTMLの構文解析で優れている:
ページを取得するには、ちょうどこの操作を行います。その後
URL url = new URL("http://upcdata.info/upc/7310870008741");
Document document = Jsoup.parse(url, 5000);
をDocument
から必要なものを解析することができます。ページの一部を抽出する方法を簡単に説明するために、このリンクをチェックアウト:
String tmpHtml = "<html>a whole bunch of html stuff</html>";
String htmlTextStr = Html.fromHtml(tmpHtml).toString();
あなたは文字列にURLから読み込みたい場合:
StringBuffer myString = new StringBuffer();
try {
String thisLine;
URL u = new URL("http://www.google.com");
DataInputStream theHTML = new DataInputStream(u.openStream());
while ((thisLine = theHTML.readLine()) != null) {
myString.append(thisLine);
}
} catch (MalformedURLException e) {
} catch (IOException e) {
}
// call toString() on myString to get the contents of the file your URL is
// pointing to.
この意志プレーンな古い文字列、HTMLマークアップ、そしてすべてをあなたに与えます。