氟塑料離心泵www.buybeng.com

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

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

          1.搜索詞的地址采用模擬地址方法(通過分析搜索引擎的參數(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ò)問題");
              }
             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();
            }
            }
          原文參考自站長網(wǎng)http://www.software8.co/wzjs/java/2692.html

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


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


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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

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

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

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網(wǎng) 氟塑料離心泵 注塑機(jī) 液晶廣告機(jī)
          主站蜘蛛池模板: 马公市| 鲁山县| 安塞县| 垦利县| 晋城| 鄄城县| 鹤庆县| 西贡区| 浦县| 岱山县| 虎林市| 五莲县| 岳阳市| 平潭县| 绥化市| 家居| 青龙| 广宁县| 松溪县| 东城区| 洛川县| 同仁县| 米易县| 珲春市| 花莲市| 花垣县| 迁西县| 全州县| 二手房| 六安市| 昂仁县| 平谷区| 保靖县| 芒康县| 哈巴河县| 镇安县| 苗栗县| 石楼县| 保德县| 灵丘县| 湘西|