初识网络爬虫之二:httplib与urllib实现
2017-10-20 22:13
323 查看
#coding:utf8 #GET请求 import httplib conn = None try: conn = httplib.HTTPConnection("www.baidu.com") conn.request("GET", "/") response = conn.getresponse() print response.status, response.reason print '-' * 40 headers = response.getheaders() for h in headers: print h print '-' * 40 print response.msg except Exception,e: print e finally: if conn: conn.close() #POST请求 import httplib, urllib conn = None try: params = urllib.urlencode({'name': 'qiye', 'age':22}) headers = {"Content-type": "application/x-www-form-urlencoded" , "Accept": "text/plain"} conn = httplib.HTTPConnection("www.baidu.com", 80, timeout=3) conn.request("POST", "/login", params, headers) response = conn.getresponse() print response.getheaders() #获取头信 4000 息 print response.status print response.read() except Exception, e: print e finally: if conn: conn.close()
相关文章推荐
- 基于Java HttpClient和Htmlparser实现网络爬虫代码
- 网络爬虫C实现http://blog.csdn.net/xu3737284/article/details/9614933
- 初识爬虫之一:urllib2与urllib实现
- 利用HttpClient、HtmlParser简单实现网络爬虫
- 基于HttpClient4.0的网络爬虫基本框架(Java实现)
- 一个最简单的网络爬虫的实现
- NGINX 实现内部网络的HTTP代理服务器的配置
- 异步网络爬虫的Python实现(3)
- Java利用正则实现网络爬虫
- Java使用Http实现网络图片的下载
- 用C#实现网络爬虫(一)
- .NET实现网络爬虫
- HttpClient实现简单的网络爬虫功能
- 网络爬虫之网站图片爬取-python实现
- HttpClient实现网络请求
- Java+MySQL实现网络爬虫程序
- 高性能C++网络库libtnet实现:http
- Python网页抓取urllib,urllib2,httplib[3]
- Android异步加载学习笔记之二:实现ListView中的图片数据从网络加载
- 5行python代码实现简单的网络爬虫