• HttpGet


    private static void func_httpGet(String url) {
            HttpClient httpClient = new HttpClient();
            try {
                GetMethod getMethod = new GetMethod(url);
                getMethod.getParams().setContentCharset("uft-8");
                getMethod.setRequestHeader("Accept-Encoding", "uft-8,deflate, sdch");
                getMethod.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                getMethod.setRequestHeader("Referer","http://www.0597kk.com/thread.php?fid=2");
                getMethod.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
                getMethod.setRequestHeader("User-Agent",
                        "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0) QQBrowser/9.2.5063.400");
                int statusCode = httpClient.executeMethod(getMethod);// 返回状态码200为成功,500为服务器端发生运行错误
                // System.out.println("返回状态码:" + statusCode);
                // 打印出返回数据,检验一下是否成功
                InputStream inputStream = getMethod.getResponseBodyAsStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
                StringBuffer stringBuffer = new StringBuffer();
                String str = "";
                while ((str = br.readLine()) != null) {
                    stringBuffer.append(str);
                }
                if (statusCode == 200) {
                    Document doc = Jsoup.parse(stringBuffer.toString());
                    Elements num = doc.select("div[class=readNum]").select("ul[class=cc]").select("em");
                    try {
                        System.out.println("当前阅读量:"+num.get(0).text());
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println("获取阅读量失败!");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    nginx之location匹配优先级和安全问题
    nginx--->高并发优化
    高并发处理方案
    检查Linux服务器性能
    浅谈Nginx负载均衡和F5的区别
    大数据不仅仅是海量数据
    自己实现C++的string类
    hihoCoder题目之Magic Box
    vim入门之配色方案(colorscheme)设置
    新开通博客,很是高兴
  • 原文地址:https://www.cnblogs.com/zeze/p/5646125.html
Copyright © 2020-2023  润新知