python脚本-开机自动联网

办公室的电脑开机之后,需要打开浏览器登录校园用户认证网页,输入用户名密码登录认证之后才能联网,每次都这样搞很麻烦,写了个Python脚本自动完成这个工作。

onStartup.py

#file:onStartup.py
#coding:utf-8

import datetime,urllib2

def getMeOnLine():
    #step 1:auto-authentication
    opener = urllib2.build_opener()
    opener.addheaders.append(('Cookie', 'md5_login=username%7Cpassword'))
    r = opener.open("http://192.168.254.220/1.htm").read()
    #print r.decode('gb2312').encode('UTF-8')
    
    #step 2:write log
    log='GetMeOnLine on startup at:%s
' % datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    with open('e:\GetOnlineLog.log','a') as f:
        f.write(log)
        
#execute the script code above       
getMeOnLine()

如何让win7一开机就自动运行该Python脚本?

电脑-开始-输入"shell:Startup"-回车-在打开的文件夹中放入要执行的python脚本文件即可。
参考:http://zhidao.baidu.com/question/1669758222677864027.html

原文地址:https://www.cnblogs.com/aaronhoo/p/5881941.html