httpclient 获取网页脚本 缺失内容 如题 原因 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public String GetWebsiteContent(String URL, String charset) { String website_content; StringBuffer StrBuf = new StringBuffer(); HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, 10000 ); HttpGet httpget = new HttpGet(URL); try { HttpResponse response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); if (entity != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), charset)); int l; char[] cbuf = new char[2048]; while ((l = reader.read(cbuf)) != -1) { String str = new String(cbuf); StrBuf.append(str); } } } website_content = StrBuf.toString(); } catch (Exception e) { System.out.println("open url error!!"); website_content = ""; } return website_content; } 请使用EntityUtils.toString 它有处理编码问题 谢谢 解决了大部分问题 但是还有一点问题 就是 <script>......</script> 后的一部分html也消失了 不知道原因所在 我是通过比较chrome 的page source 和 httpclient 获取的html 比较时候发现的 是这样的 <script>.........</script> 跟了一个table 然后 那个table 整个消失不见了 关于JAVA内存模型,请大家给讲解一下JAVA堆栈的问题,谢谢 red hat 下怎么在tomcat停止服务后自动重启. 用空布局后为什么一个组件都没显示出来? try-catch-finally 多种国家的语言无障碍的沟通 什么好方法循环出三角形* 关于无常正常编译servlet文件的问题.急.顺便说下导包的方法. 求助:关于swing中的JsplitPane的问题 关于繁简体转换的问题! 一道考试题,送100分,别忘了写注释啊。 [散分啦]爱思考的你...不想来看看这些题吗 关于java主函数main()的问题,盼大神指教。
String website_content;
StringBuffer StrBuf = new StringBuffer(); HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, 10000 );
HttpGet httpget = new HttpGet(URL);
try {
HttpResponse response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
if (entity != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), charset));
int l;
char[] cbuf = new char[2048];
while ((l = reader.read(cbuf)) != -1) {
String str = new String(cbuf);
StrBuf.append(str);
} }
}
website_content = StrBuf.toString(); } catch (Exception e) {
System.out.println("open url error!!");
website_content = "";
} return website_content;
}
请使用EntityUtils.toString 它有处理编码问题