首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 装配easy_install工具(转)

2012-12-26 
python 安装easy_install工具(转)easy_install 安装软件 及BeautifulSoup 中文乱码安装easy_install工具使

python 安装easy_install工具(转)

easy_install 安装软件 及BeautifulSoup 中文乱码


安装easy_install工具

使用ez_setup.py脚本方便安装:

python 装配easy_install工具(转)wget?-q?http://peak.telecommunity.com/dist/ez_setup.py
python 装配easy_install工具(转)python?ez_setup.py


安装完后,最好确保easy_install所在目录已经被加到PATH环境变量里:

python 装配easy_install工具(转)Windows:?C:\Python25\Scripts
python 装配easy_install工具(转)Linux:?/usr/local/bin
python 装配easy_install工具(转)

安装 Mechanize 和 BeautifulSoup

安装Mechanize 和 BeautifulSoup,可以执行如下命令,系统会自动在pypi网站列表里查找相关软件包:

python 装配easy_install工具(转)easy_install?Mechanize
python 装配easy_install工具(转)easy_install?BeatifulSoup

BeautifulSoup中文乱码

简单的一段代码:

python 装配easy_install工具(转)from?BeautifulSoup?import?BeautifulSoup?
python 装配easy_install工具(转)
python 装配easy_install工具(转)page?=?"<a><s>中文</s></a>"
python 装配easy_install工具(转)soup?=?BeautifulSoup(page,?fromEncoding="utf-8")
python 装配easy_install工具(转)print?soup
python 装配easy_install工具(转)f?=?open("ss.txt",?"w+")
python 装配easy_install工具(转)f.write(str(soup))
python 装配easy_install工具(转)f.close()
打印出来的乱码,写入文件却是正常的。查了一下,这个跟shell的编码有关,windows的一般是gbk,所以utf-8出乱码很正常,如果要正常打印,只要把字符串转换成指定编码方式就可以。

热点排行