氟塑料離心泵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 你爸是李剛 閱讀(2159) 評論(0)  編輯  收藏


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


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

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 辛集市| 同江市| 耿马| 治县。| 东乌珠穆沁旗| 响水县| 清水河县| 平顶山市| 泰安市| 澎湖县| 巴林左旗| 襄垣县| 剑川县| 唐山市| 武邑县| 睢宁县| 象山县| 新闻| 河西区| 微博| 新绛县| 克山县| 望都县| 临洮县| 汶川县| 洪湖市| 乌海市| 修文县| 麻栗坡县| 伊金霍洛旗| 长汀县| 家居| 增城市| 土默特左旗| 安仁县| 平谷区| 扬中市| 崇仁县| 张掖市| 平定县| 阿拉善右旗|