2011-01-14 8 views

答えて

7

Jsoupは、Androidアプリケーションから簡単なHTMLの構文解析で優れている:

http://jsoup.org/

ページを取得するには、ちょうどこの操作を行います。その後

URL url = new URL("http://upcdata.info/upc/7310870008741"); 
Document document = Jsoup.parse(url, 5000); 

Documentから必要なものを解析することができます。ページの一部を抽出する方法を簡単に説明するために、このリンクをチェックアウト:

http://jsoup.org/cookbook/extracting-data/dom-navigation

1
String tmpHtml = "<html>a whole bunch of html stuff</html>"; 
String htmlTextStr = Html.fromHtml(tmpHtml).toString(); 
2

あなたは文字列に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マークアップ、そしてすべてをあなたに与えます。