第6课 python函数之第三方函数的安装和使用

来源:互联网 发布:单片机键盘输入 编辑:程序博客网 时间:2024/05/21 06:50
1.如何安装使用Python第三方函数库
函数库httplib2
1)下载模块
下载地址:https://pypi.python.org/pypi/httplib2
2)解压下载的压缩包“httplib2-0.9.1.zip”到某目录下
3)配置python在dos下的运行环境

(之前需要配置系统环境变量,在系统环境变量Path后添加python安装目录,例如d:/python) 


4)在系统变量变量名为Path的变量值中添加Python的安装路径,同样在PATHEXT中添加 .PY;.PYM


5)在dos下安装httplib2模块


使用第三方函数库实现打开浏览网页

>>> import urllib

>>> importwebbrowser

>>>url='http://www.163.com'

>>> content=urllib.urlopen(url).read()

>>> print content

 <!DOCTYPE HTML>

<!--[if IE 6 ]><html class="ne_ua_ie6 ne_ua_ielte8"> <![endif]-->

<!--[if IE 7 ]><html class="ne_ua_ie7 ne_ua_ielte8"> <![endif]-->

<!--[if IE 8 ]><html class="ne_ua_ie8 ne_ua_ielte8"> <![endif]-->

<!--[if IE 9 ]><html class="ne_ua_ie9"> <![endif]-->

………….

>>>open('163.com.html','w').write(content)

>>>webbrowser.open_new_tab('163.com.html')

True

其中webbrowser.open_new_tab为打开指定的网页



1 0