複製可用。
/**
* Get a page's source code
* @param strUrl Url of this page
* @param charset Charset of this page, like "utf-8","gbk"
* @return
* @throws IOException
*/
public String fetchHtml(String strUrl, String charset) throws Exception
{
if (!strUrl.startsWith("http://"))
strUrl = "http://" + strUrl;
URL url = new URL(strUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
InputStream is = con.getInputStream();
InputStreamReader isr = new InputStreamReader(is, charset);
String html = "";
int read;
for (; (read = isr.read()) != -1; )
html += (char) read;
isr.close();
return html;
}