vickzhu

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  151 随笔 :: 0 文章 :: 34 评论 :: 0 Trackbacks

       我要抓取的页面的完整路径为:http://www.google.cn/language_tools?hl=zh-CN

       String strServer=
"www.google.cn";//这里同样可以用ip来访问:203.208.35.100

       String strPage="/language_tools?hl=zh-CN";

       try {

           String hostname = strServer;

           int port = 80;

           InetAddress addr = InetAddress.getByName(hostname);

           Socket socket = new Socket(addr, port);

           BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));

           wr.write("GET " + strPage + " HTTP/1.0"r"n");

           wr.write("HOST:" + strServer + ""r"n");

           wr.write(""r"n");

           wr.flush();

           BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));

           String line;

           while ((line = rd.readLine()) != null) {

              System.out.println(line);

           }

           wr.close();

           rd.close();

       } catch (Exception e) {

           System.out.println(e.toString());

       }

posted on 2008-08-14 16:52 筱 筱 阅读(406) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: