1、httpclient
httpclient能够当做一个无界面的浏览器,通过httpclient获取网站信息
2、代码奉上
采用maven,插入依赖
org.apache.httpcomponents
httpclient
4.5.8
测试
public static void main(String[] args) {
String url=“www.baidu.com”;
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response = httpClient.execute(httpGet);
//注意编码,如果设置不当会出现乱码
String html = EntityUtils.toString(response.getEntity(), “utf-8”);
System.out.println(html);
}
更多技术交流加q:337292404