python3 基于urllib模块的网络编程
2015-11-30 18:59
555 查看
import urllib.request def demo(): """ 打开和读取URL网络资源 """ f=urllib.request.urlopen('http://www.baidu.com') str=f.read(2000).decode('utf-8') print(str) def getURLInfo(url,data,headers): """ 创建Request对象 """ req=urllib.request.Request(url,data,headers) print('Full url : ',req.full_url) print('Host : ',req.host) print('Data : ',req.data) if __name__ == '__main__': url='http://www.baidu.com' values={'wd':'python'} data=urllib.parse.urlencode(values) data=data.encode(encoding='UTF-8') headers={'User-Agent':'Mozilla/4.0(compatoble;MSIE 5.5;Windows NT)'} getURLInfo(url,data,headers)
相关文章推荐
- Ubuntu Server Guide ☞ 联网 ☞ 网络配置
- http://elf8848.iteye.com/blog/1739596
- HTTP 代理如何正确处理 Cookie
- HttpClient基本用法
- Qt tcp 通信
- http 状态码含义
- delphi idHttp下载文件
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- 人工神经网络简介和单层网络实现AND运算--AForge.NET框架的使用(五)
- Xcode UI做从网络上获取图片的时候需要改的东西
- python 3 TCP简单小程序
- The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from
- webview显示https协议内容
- iOS如何在工程中使用第三方(网络)图片
- PEP 0476 -- Enabling certificate verification by default for stdlib http clients
- 用netstat对TCP状态分析
- 关于http请求和webservice请求的了解?
- java Tcp/Udp区别
- iOS开发网络篇—文件的上传
- iOS开发网络篇—监测网络状态