初识网络爬虫之二:httplib与urllib实现
来源:互联网 发布:淘宝网雪纺女装 编辑:程序博客网 时间:2024/06/01 09:24
#coding:utf8#GET请求import httplibconn = Nonetry: 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.msgexcept Exception,e: print efinally: if conn: conn.close()#POST请求import httplib, urllibconn = Nonetry: 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() #获取头信息 print response.status print response.read()except Exception, e: print efinally: if conn: conn.close()
阅读全文
0 0
- 初识网络爬虫之二:httplib与urllib实现
- 初识爬虫之一:urllib2与urllib实现
- python 网络编程httplib/httplib2/urllib/urllib2
- 网络爬虫之初识网络爬虫
- Python模块之---urllib,urllib2,httplib
- python标准库之urllib, httplib, urllib2
- Python爬虫入门二之Urllib库的高级用法
- Python urllib&urllib2&httplib
- Python网络爬虫与信息提取(二):网络爬虫之提取
- Python网络爬虫与信息提取(二):网络爬虫之提取
- Python爬虫之urllib介绍
- JAVA爬虫初识之httpclient与jsoup
- JAVA爬虫初识之httpclient与jsoup
- 初识网络爬虫
- Scrapy网络爬虫----初识
- 初识网络爬虫
- 初识网络爬虫
- Python3网络爬虫(二):利用urllib.urlopen向有道翻译发送数据获得翻译结果
- 蚂蚱跳跃(移动距离)
- ANDROID中使用开源框架ANDROID-IMAGE-INDICATOR实现图片轮播部署
- Log4j的简单使用
- UML用例图
- 面试小记2
- 初识网络爬虫之二:httplib与urllib实现
- Python初级教程
- Linux教程【8】-文件搜索命令
- 四、关于osmdroid地图源的疑问
- linked-list-cycle
- 银行业务对列简单模拟
- 3、jQuery的属性与样式--样式篇
- 初始网络爬虫之三:网络爬虫最常用的requests库
- php微信开发解决{"errcode":40016,"errmsg":"invalid button size hint: [pqd5ea0809vr22]"}