Java HttpClient 网络爬虫怎么使用
2015-10-06 21:17
537 查看
1,解压httpcomponents-client-4.2.5-bin.zip
拷贝依赖包:
commons-codec-1.6.jar
commons-logging-1.1.1.jar
fluent-hc-4.2.5.jar
httpclient-4.2.5.jar
httpclient-cache-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
2,写一个Java类
拷贝依赖包:
commons-codec-1.6.jar
commons-logging-1.1.1.jar
fluent-hc-4.2.5.jar
httpclient-4.2.5.jar
httpclient-cache-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
2,写一个Java类
package com.chuangfuwu.httpclient; import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; public class Test { public static void main(String[] args) throws ClientProtocolException, IOException { HttpGet httpGet = new HttpGet("http://www.baidu.com"); HttpClient httpClient=new DefaultHttpClient(); HttpResponse httpResponse = httpClient.execute(httpGet); String htmlString=EntityUtils.toString(httpResponse.getEntity()); System.out.println(htmlString); } }
相关文章推荐
- 《UNIX网络编程》中的unp.h和config.h
- 计算机网络—常考内容
- TCP与UDP的应用
- JAVA基础学习之UDP网络编程
- HDU4280 Island Transport 网络流模版题
- 浏览器输入URL后,到网页响应的全过程
- TCP/IP详解卷1:第十四章 DNS 域名系统
- 【HTTP】如何正常关闭连接
- http/https 介绍 ----Secure Hypertext Transfer Protocol 安全超文本传输协议
- 《UNIX网络编程》学习笔记:基本TCP套接字编程
- ns-2与TCP拥塞模拟 之一 一个简单的示例说明基本要素
- 网络广告假流量盛行,查处有妙招
- [iOS进阶]Socket 网络编程
- HTTP 协议详解(基础)
- (转)HTTP 协议详解(基础)
- Socket所有的网络通信模型详解共享
- HTTP协议漫谈
- (转)HTTP协议漫谈
- python 网络编程(一):socket 模块
- 基于TCP网络通信的简易多线程GUI聊天室