【脚本语言系列】关于PythonWeb客户端-服务器模块http-urllib,你需要知道的事情
来源:互联网 发布:产品经理画图软件 编辑:程序博客网 时间:2024/06/01 09:20
如何使用http/urllib
使用urllib访问百度
# -*- coding:utf-8 -*-import urllib.request as ururl = "http://www.baidu.com"conn = ur.urlopen(url)print conndata = conn.read()print data
---------------------------------------------------------------------------ImportError Traceback (most recent call last)<ipython-input-4-a26b59fb666e> in <module>() 1 ----> 2 import urllib.request as ur 3 url = "http://www.baidu.com" 4 conn = ur.urlopen(url) 5 print connImportError: No module named request
解决使用urllib访问百度的报错
问题:导入错误:ImportError: No module named request
解决方案:import urllib2 as ur替换import urllib.request as ur
# -*- coding:utf-8 -*-import urllib2 as ururl = "http://www.baidu.com"conn = ur.urlopen(url)print conndata = conn.read()print data
<addinfourl at 110377288L whose fp = <socket._fileobject object at 0x0000000006907C00>><!DOCTYPE html><!--STATUS OK--><html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <meta content="always" name="referrer"> <meta name="theme-color" content="#2932e1"> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" /> <link rel="icon" sizes="any" mask href="//www.baidu.com/img/baidu.svg"> <link rel="dns-prefetch" href="//s1.bdstatic.com"/> <link rel="dns-prefetch" href="//t1.baidu.com"/> <link rel="dns-prefetch" href="//t2.baidu.com"/> <link rel="dns-prefetch" href="//t3.baidu.com"/> <link rel="dns-prefetch" href="//t10.baidu.com"/> <link rel="dns-prefetch" href="//t11.baidu.com"/> <link rel="dns-prefetch" href="//t12.baidu.com"/> <link rel="dns-prefetch" href="//b1.bdstatic.com"/> <title>百度一下,你就知道</title>省略大部分HTML...</body></html><script src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/yunying/Turing2017PC/logo_1.6.js"></script>
什么是http/urllib
http是客户端-服务器模块,包括4个部分:
* client处理客户端请求
* server处理服务器响应
* cookies和cookiejar处理cookie
urllib是基于http的封装库,包括3个部分:
* request模块处理客户端请求
* response处理服务器的响应
* parse解析url
模块结构比较松散,既包含服务器模块request,又包含客户端模块response
为何使用http/urllib
以上标准库标准库会在Python3.x中进行改进;如果想要快速开发客户端,建议使用request库.
阅读全文
0 0
- 【脚本语言系列】关于PythonWeb客户端-服务器模块http-urllib,你需要知道的事情
- 【脚本语言系列】关于PythonWeb客户端标准库requests,你需要知道的事情
- 【脚本语言系列】关于PythonWeb访问urllib,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化webbrowser模块,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Bottle,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Flask,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器apache+mod_wsgi,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Nginx+uWSGI,你需要知道的事
- 【脚本语言系列】关于PythonWeb访问ftplib,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化BeautifulSoup,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化REST,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化Web API,你需要知道的事
- 【脚本语言系列】关于Python音频处理WMPlayerOCX,你需要知道的事情
- 【脚本语言系列】关于Python操作数据二进制数据,你需要知道的事情
- 【脚本语言系列】关于Python数据库访问专用模块,你需要知道的事
- 【脚本语言系列】关于Python进程线程管理系统模块,你需要知道的事
- 【脚本语言系列】关于Python系统管理,你需要知道的事
- 【脚本语言系列】关于Python容器,你需要知道的事
- jQuery小记(三)
- zabbix 监控Windows client
- python-检验33品种数据是否是正态分布
- 微信小程序(一)
- Argument(s) are different! Wanted:
- 【脚本语言系列】关于PythonWeb客户端-服务器模块http-urllib,你需要知道的事情
- mysql sum 统计数值出现精度问题
- ios友盟cocos微信登陆回调回原来程序的配置问题
- 《深入理解mybatis原理》 Mybatis数据源与连接池
- 使用Jenkins进行持续集成
- mybatis入门基础(二)----原始dao的开发和mapper代理开发
- 雄狮 电影 百度云资源
- centos 7.2 安装erlang19.3
- 关于Java基本数据类型与引用数据类型的简述