Java获取网页源代码
设置url为想查看源代码的网址
import java.net.*;
import java.io.*;
public class GetHtml {
public static void main(String[] args) throws Exception{
// TODO 自动生成的方法存根
URL url1 = new URL("http://www.weather.com.cn/");//中国天气网(可以改成其他网站的网址)
InputStream inStream = url1.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(inStream,"utf-8"));
String line;
while((line = in.readLine())!=null) {
System.out.println(line);
}
in.close();
}
}