隨筆-10  評論-10  文章-0  trackbacks-0
            2007年5月8日


          import java.io.*;
          import java.net.*;


          /**
          * 獲取一個網頁的源代碼
          * @author Tony
          */
          public class GetCode {

          //方法:獲取網頁的源代碼 
          public static String getNetcode(String spec)
          {
           String line = null;
           String temp = null;
           try{
             URL url=new URL(spec); //設置URL
            
             HttpURLConnection uc = (HttpURLConnection)url.openConnection();//打開連接
             //獲取到輸入流
             BufferedReader in=new BufferedReader(new InputStreamReader(uc.getInputStream()));
           
             while((line=in.readLine())!=null)
             {
              temp+=line;//向temp里添加網頁代碼
             }
             if(in!=null)
             in.close();
            }
            catch(Exception e)
            {
             e.printStackTrace();
            }
            
            return temp;
          }
          /**
          * @param args
          */
          public static void main(String[] args) {
           
           String bookName = "傻B巴西的卡卡";//最初要搜尋的漫畫名稱
           String category = "漫畫"; //類型
           String sendName; //實際發送的漫畫名稱關鍵字
           String url = null;//發送去的url地址
           
            try
            {
             sendName = URLEncoder.encode(bookName,"gb2312");
             //實際發送的漫畫類型
             String sendCategory = URLEncoder.encode(category,"gb2312");
             //整合url 并帶上查詢關鍵子、類型
             url = new String("

             //打印出得到的網頁代碼
             System.out.println(getNetcode(url));
            }
            catch(Exception e)
            {
             e.printStackTrace();
            }

           

           }
          }



          代碼如上。這個代碼對于baidu首頁的源代碼能夠正常獲取到,但對baidu顯示查詢結果頁面卻不能獲取到,報錯為:Unexpected end of file from server   請問為什么呢?有什么解決方法嗎?
          posted @ 2007-05-25 14:40 細雨游風 閱讀(725) | 評論 (0)編輯 收藏
              請問下JAVA哥哥,我想寫個程序:輸入查詢關鍵字,然后調用baidu or google的數據庫進行查詢,然后返回前10條結果給我。 有什么辦法嗎? 先在此謝謝您~!
          posted @ 2007-05-21 14:26 細雨游風 閱讀(282) | 評論 (0)編輯 收藏
          如何判斷一個字符串是繁體編碼還是簡體編碼?????????
          posted @ 2007-05-08 13:21 細雨游風 閱讀(2385) | 評論 (2)編輯 收藏
          主站蜘蛛池模板: 定州市| 卫辉市| 略阳县| 江达县| 寻乌县| 民权县| 阿勒泰市| 墨竹工卡县| 建始县| 武川县| 隆回县| 平原县| 太白县| 嘉义市| 尚义县| 江城| 阳信县| 长春市| 泗阳县| 奉新县| 长沙市| 瑞昌市| 东乌珠穆沁旗| 陆良县| 宁陵县| 北辰区| 临夏县| 化德县| 昭平县| 利辛县| 扎赉特旗| 彭州市| 集安市| 马龙县| 横山县| 科尔| 武平县| 甘孜县| 高平市| 庐江县| 紫金县|