闲着没事,也算练练手,试了一下py2exe,还很好用的
先写一个准备执行的程序,其实是调用IE访问一个网页,提交用户名和密码,这样就可以实现自动登陆了
2.py
Code
#!/usr/bin/env python
#coding=utf-8
import win32com.client
import time
ie7 = win32com.client.Dispatch("InternetExplorer.Application")
ie7.Navigate('https://*****/auth/requireLogin')
ie7.Visible =1
while ie7.Busy:
time.sleep(1)
try:
document = ie7.Document
document.getElementById("username").value='123'
document.getElementById('password').value='123'#用户名和密码虚构的
document.forms[0].submit()
except:
pass
然后写py2exe的打包程序waf.py,还为程序加了一个ico图标
Code
#!/usr/bin/env python
#coding=utf-8
from distutils.core import setup
import py2exe
includes = ['encodings','encodings.*']
options = {'py2exe':{'compressed':1,'optimize':2,'includes':includes,'bundle_files':1}}
setup(version='0.1.0',description='WAF LOGIN',name='WAF-LOGIN',options=options,zipfile=None,windows=[{'script':'2.py',"icon_resources":[(1,'waf.ico')]}])
好了,然后执行python waf.py py2exe,一切ok
直接运行生成的dist目录下的2.exe就可以了 呵呵
注意,waf.py中,我设置了'bundle_files':1,这样必要的模块、程序都打包在.exe中,即.exe文件可以单独存在去执行了。