python---easy_install 安装软件 及BeautifulSoup 中文乱码

安装easy_install工具

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

wget  - q http: // peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py


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

Windows: C:\Python25\Scripts
Linux: 
/ usr / local / bin


安装 Mechanize 和 BeautifulSoup

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

easy_install Mechanize
easy_install BeatifulSoup


BeautifulSoup中文乱码

简单的一段代码:


from  BeautifulSoup  import  BeautifulSoup 

page 
=   " <a><s>中文</s></a> "
soup 
=  BeautifulSoup(page, fromEncoding = " utf-8 " )
print  soup
=  open( " ss.txt " " w+ " )
f.write(str(soup))
f.close()
打印出来的乱码,写入文件倒是正常的。查了一下,这个跟shell的编码有关,windows的通常是gbk,因此utf-8出乱码很正常,若是要正常打印,只要把字符串转换成指定编码方式就能够。
相关文章
相关标签/搜索