读书人

在android客户端加载html源代码小结

发布时间: 2013-10-13 14:03:53 作者: rapoo

在android客户端加载html源代码总结

在实际应用中,客户端要从网页上获取数据是常见的事,如果要解析网页上的html文档,那么首先得获取html源码,然后现在一般使用Jsoup来转换成Document文档来进行解析,本文主要讨论如何使用Jsoup把html文档解析成Document文档,方法归纳了6种,jar使用的是jsoup-1.6.1.jar,代码如下:

MainActivity:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <Button        android:id="@+id/main_btn"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="加载" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="html源码:" />    <EditText        android:id="@+id/main_et"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:editable="false" /></LinearLayout>

记得加上访问网络和读取sd卡文件的权限哦~。

读书人网 >CSS

热点推荐