java抓取网页信息内容

	CloseableHttpClient httpclient = HttpClients.createDefault(); 
        HttpGet httpget = new HttpGet(net.trim());
        httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0"); // ��������ͷ��ϢUser-Agent
        String state = "";
        String content;
		try {
			 CloseableHttpResponse response = httpclient.execute(httpget);
		        HttpEntity entity=response.getEntity(); 
			content = EntityUtils.toString(entity, "utf-8");
			//输出content就可以看到抓取的网页内容
	        response.close();
	        httpclient.close(); 
	 
		}catch (SocketException exception) {
			
		}catch (Exception e) {
			
		}                     
	

你可能感兴趣的:(java抓取网页信息内容)