我要抓取的页面的完整路径为: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());
}