2011-01-14 2 views

ответ

7

Jsoup отлично при разборе простой HTML из Android приложений:

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-разметку и все.

Смежные вопросы