问题描述
搜狐评论列表url: http://comment.news.sohu.com/djpm/我想得到里头的热门新闻。用了httpclient+htmlcleaner 还是不行原因:请求到的html文件是一堆乱码,用了gbk(页面中设置的charset是gbk), utf-8, utf-16, ascii都还是不行。请问各位大侠:有什么其它比较好的方法可以解决这个问题?或者除了httpclient外还有没有更好的请求网页的工具?求解答,不甚感激! 问题补充:flootball 写道
解决方案
HttpClient httpClient=new HttpClient();GetMethod getMethod = null;BufferedReader br=null;BufferedWriter bw=null;getMethod=new GetMethod(url);getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());int statusCode = httpClient.executeMethod(getMethod);if (statusCode != HttpStatus.SC_OK) {System.err.println("Method failed: " + getMethod.getStatusLine()); } br=new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream(),"UTF-8"));其余的代码自己补全。用这个试试吧。
解决方案二:
贴出代码看看。。!我这连不上搜狐.
解决方案三:
看看网页源码是何物?网页源码能看见内容,那httpclient就能取下来。获取内容的规则:分析下内容就好了。