1. 程式人生 > >java 爬取1網頁內容

java 爬取1網頁內容

package testDeployActivity;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class TestUrl 
{
	public static void main(String[] args) throws Exception {
		URL url=new URL("https://www.baidu.com");
		URLConnection conn=url.openConnection();
		BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8" ));
		String str=null;
		while((str=br.readLine())!=null)
		{
			System.out.println(str);
		}
		
	}
}