chaoren3166 2010-11-29 15:40
浏览 242
已采纳

请问用什么方法可以获取搜狐评论排行中的新闻列表

搜狐评论列表url: http://comment.news.sohu.com/djpm/
我想得到里头的热门新闻。
用了httpclient+htmlcleaner 还是不行
原因:请求到的html文件是一堆乱码,用了gbk(页面中设置的charset是gbk), utf-8, utf-16, ascii都还是不行。

请问各位大侠:有什么其它比较好的方法可以解决这个问题?或者除了httpclient外还有没有更好的请求网页的工具?
求解答,不甚感激!

  • 写回答

3条回答 默认 最新

  • Wang_Cheng_Bing 2010-12-01 10:16
    关注

    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"));

    其余的代码自己补全。
    用这个试试吧。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法