cx_freeze和py2exe打包py程序笔记
2010年5月20日 03:53
环境: python 2.6 win7 cx_freeze4.1.2 py2exe-0.6.9.win32-py2.6
cx_freeze打包tkinter程序的话,setup.py里写入tk\tcl目录如:
# -*- coding: utf-8 -*- from cx_Freeze import setup, Executable includeFiles = [ ( r"D:\lib\Python26\tcl\tcl8.5", "tcl"), ( r"D:\lib\Python26\tcl\tk8.5", "tk") ] setup( name = "hello", version = "0.1", description = "Sample cx_Freeze script", options = {"build_exe": {"include_files": includeFiles,}}, executables = [Executable("test.py",base="Win32GUI")])
(命令行程序去掉base那个选项)
在当前目录下执行(需把python地址加入环境变量):
python setup.py build
py2exe的setup.py写成:
# -*- coding: utf-8 -*-
# setup.py
from distutils.core import setup
import py2exe
setup(windows=["mine.pyw"])
不用像cx_freeze在意tkinter,命令行程序把最后一行的windows换成console
在当前目录下执行:
python setup.py py2exe
OK! 笔记完成!
补充:
py2exe打包wxpython程序时遇到找不到msvcp9.dll
需下载MSVCP90.DLL 并拷贝到Python26/DLLs 目录下
setup.py写成:
# -*- coding: utf-8 -*- # setup.py from distutils.core import setup import py2exe setup( windows=["test.pyw"], options = { "py2exe": {"dll_excludes":["MSVCP90.dll"]} } )
Python 抓取小说爬虫
2010年4月14日 06:52
Python好神奇!爬虫原来是这个样子的!抓网页原来这么简单!
import urllib2 from BeautifulSoup import BeautifulSoup content = urllib2.urlopen( 'http://www.feiku.com/html/book/130/159571/4747141.shtm' ).read() soup = BeautifulSoup(content) soup=soup.find('div', id="BookText") f = file('book.txt', 'w') for i in soup.findAll(text=True): i=i.replace(' ',' ') f.write(i.encode('utf-8')+'\n') f.close()