希望能帮到你 . . . 这个可以解决你的问题 但是没有样式的.只是爬了源代码
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
public class WebPageSource {
public static void main(String args[]){
URL url;
int responsecode;
HttpURLConnection urlConnection;
BufferedReader reader;
BufferedWriter writer;
String line;
try{
//生成一个URL对象,要获取源代码的网页地址为:http://www.sina.com.cn
url=new URL("http://www.sina.com.cn");
//打开URL
urlConnection = (HttpURLConnection)url.openConnection();
//获取服务器响应代码
responsecode=urlConnection.getResponseCode();
if(responsecode==200){
//得到输入流,即获得了网页的内容
reader=new BufferedReader(new InputStreamReader(urlConnection.getInputStream(),"GBK"));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("d://test.txt"))));
while((line=reader.readLine())!=null){
writer.write(line);
writer.newLine();
}
}
else{
System.out.println("获取不到网页的源码,服务器响应代码为:"+responsecode);
}
}
catch(Exception e){
System.out.println("获取不到网页的源码,出现异常:"+e);
}
}
}