1.Android 中獲取html源代碼 html
public String getHtmlString(String urlString) {
try {
URL url = new URL(urlString);
URLConnection ucon = url.openConnection();
InputStream instr = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(instr);
ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
return EncodingUtils.getString(baf.toByteArray(), "UTF-8");
} catch (Exception e) {
return e.getMessage();
}
}
或者亦能夠用jsoup直接獲取html app
2.只要將jsoup的jar文件加入libs文件夾中便可在工程中使用jsoup,jsoup 中文版的使用手冊 url