氟塑料離心泵www.buybeng.com

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

          java爬取網(wǎng)頁(yè)源代碼,解析

          1.搜索詞的地址采用模擬地址方法(通過(guò)分析搜索引擎的參數(shù)得到,如百度),然后將搜索詞加到模擬的地址中。
          2.函數(shù)的輸入?yún)?shù)是模擬地址。
          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("網(wǎng)絡(luò)問(wèn)題");
              }
             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();
            }
            }
          原文參考自站長(zhǎng)網(wǎng)http://www.software8.co/wzjs/java/2692.html

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


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術(shù)網(wǎng)站

          行業(yè)網(wǎng)站

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          站長(zhǎng)網(wǎng) 氟塑料離心泵 注塑機(jī) 液晶廣告機(jī)
          主站蜘蛛池模板: 安顺市| 黄平县| 吐鲁番市| 柳河县| 临夏县| 藁城市| 云梦县| 龙口市| 沙河市| 会同县| 兰坪| 福州市| 五峰| 庆元县| 凉山| 五原县| 泰安市| 宜州市| 蓝田县| 台湾省| 兴隆县| 安泽县| 腾冲县| 平湖市| 上栗县| 长春市| 郯城县| 政和县| 伊川县| 桓台县| 伊金霍洛旗| 萍乡市| 大安市| 绵阳市| 沛县| 大埔区| 巴林左旗| 普兰县| 同江市| 南充市| 扎鲁特旗|