python 安装easy_install工具(转)
安装easy_install工具
使用ez_setup.py脚本方便安装:
wget?-q?http://peak.telecommunity.com/dist/ez_setup.py
python?ez_setup.py
安装完后,最好确保easy_install所在目录已经被加到PATH环境变量里:
Windows:?C:\Python25\Scripts
Linux:?/usr/local/bin
安装 Mechanize 和 BeautifulSoup
安装Mechanize 和 BeautifulSoup,可以执行如下命令,系统会自动在pypi网站列表里查找相关软件包:
easy_install?Mechanize
easy_install?BeatifulSoupBeautifulSoup中文乱码
简单的一段代码:
from?BeautifulSoup?import?BeautifulSoup?
page?=?"<a><s>中文</s></a>"
soup?=?BeautifulSoup(page,?fromEncoding="utf-8")
print?soup
f?=?open("ss.txt",?"w+")
f.write(str(soup))
f.close()打印出来的乱码,写入文件却是正常的。查了一下,这个跟shell的编码有关,windows的一般是gbk,所以utf-8出乱码很正常,如果要正常打印,只要把字符串转换成指定编码方式就可以。