氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          java爬取網頁源代碼,解析

          1.搜索詞的地址采用模擬地址方法(通過分析搜索引擎的參數得到,如百度),然后將搜索詞加到模擬的地址中。
          2.函數的輸入參數是模擬地址。
          String query = URLEncoder.encode("潘柱廷", "UTF-8");
          String url="http://www.baidu.com/s?wd="+query+"&pn="+p*10+"&tn=baiduhome_pg&ie=utf-8"
          public void MakeQuery(String domain) {
            try {
             HttpClient httpClient = new HttpClient();
             GetMethod getMethod = new GetMethod(domain);
             
             //System.out.println("*************************************************************");
             //System.out.println(getMethod);
             try{
              httpClient.executeMethod(getMethod);
              }catch(Exception e){
               System.out.println("網絡問題");
              }
             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());
             }
             
             byte[] responseBody = getMethod.getResponseBody();
             
             //System.out.println("*************************************************************");
             //System.out.println(responseBody);
             
             
             String response = new String(responseBody, "UTF-8");
             
             //System.out.println("*************************************************************");
             //System.out.println(response);
             
             //Jsoup解析html
             Document doc=Jsoup.parse(response);
             //System.out.println("*************************************************************");
             //System.out.println(doc);
            
             Elements contents=doc.getElementsByClass("f");
             for(Element content:contents){
           
             Element links = content.getElementsByTag("a").first();
               String linkHref = links.attr("href");//鏈接
               String linkText = links.text();//摘要
               FoursearchZH.map.put(linkHref, linkText);
               
               System.out.println("------------------");
               System.out.println(linkHref);
                  System.out.println(linkText);
              }
            } catch (Exception e) {
             System.err.println("Something went wrong...");
             e.printStackTrace();
            }
            }
          原文參考自站長網http://www.software8.co/wzjs/java/2692.html

          posted on 2013-01-16 12:36 你爸是李剛 閱讀(2161) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 建水县| 滦南县| 安福县| 洞口县| 内黄县| 原平市| 左贡县| 武平县| 甘孜县| 溧水县| 建始县| 通江县| 吉隆县| 通榆县| 宁波市| 湘潭县| 当阳市| 新化县| 昆山市| 河曲县| 邯郸县| 南岸区| 泰安市| 武乡县| 横山县| 贺州市| 修水县| 巩留县| 青龙| 嘉禾县| 唐海县| 丰都县| 宝坻区| 靖西县| 车险| 沛县| 柳州市| 长宁县| 共和县| 兴隆县| 北辰区|