我想从页面解析出一些文本。android:从页面012解析html
有没有简单的方法可以将产品信息保存到字符串中?例如网址:http://upcdata.info/upc/7310870008741
感谢
我想从页面解析出一些文本。android:从页面012解析html
有没有简单的方法可以将产品信息保存到字符串中?例如网址: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标记和所有。