电脑需预先安装好python(包括相应python库)和浏览器驱动chromedriver
在电脑任意位置创建下面两个文件:
1 2 3 4 5 6 7 8 9 ### 文件1:filename1.bat ### @echo off if "%1"=="hide" goto CmdBegin start mshta vbscript:createobject("wscript.shell").run("""%~0"" hide",0)(window.close)&&exit :CmdBegin #以上部分为设置bat运行时不显示窗口 set ssid="***校园网名称***" netsh wlan connect name=%ssid% python filename2.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 from selenium import webdriverfrom selenium.webdriver.support.ui import Selectfrom selenium.webdriver.chrome.options import Optionsimport timeopt=Options() opt.add_argument("--headless" ) if __name__ =="__main__" : driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe" ,opt) driver.get('http://10.211.220.9/0.htm' ) driver.find_element_by_id("username" ).send_keys("***用户名***" ) s=Select(driver.find_element_by_id("suffix" )) s.select_by_value("2" ) driver.find_element_by_id("password" ).send_keys("***密码***" ) driver.find_element_by_xpath('//input[@type="submit"][@value="登 录"]' ).click() time.sleep(0.5 ) driver.quit()
WIN+R,输入taskschd.msc
回车,打开任务计划程序,创建任务。
尝试后发现本文代码确实能够实现联网操作,但每次开机时其执行效果不好,无法及时有效运行。