自动签到脚本
#!/usr/bin/env python
#coding = utf-8
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
import pywifi
import os
import time
import sys
myusername1 = "15651078606"#帐号
mypassword1 = "WXYZ0179"#密码
myusername2 = "051510623"#校园网账号
mypassword2 = "142857"#校园网密码
myusername3 = "02502124090"#联通网账号
mypassword3 = "123123"#联通网密码
def ConnectCh():#连接ChinaUnicom,WIFI
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.disconnect()#断开网卡连接
time.sleep(3)#缓冲3秒
profile = pywifi.Profile()#配置文件
profile.ssid = "ChinaUnicom"#wifi名称
profile.auth = pywifi.const.AUTH_ALG_OPEN#需要密码
profile.akm.append(pywifi.const.AKM_TYPE_NONE)#加密类型
profile.cipher = pywifi.const.CIPHER_TYPE_NONE#加密单元
iface.remove_all_network_profiles()#删除其他配置文件
tmp_profile = iface.add_network_profile(profile)#加载配置文件
iface.connect(tmp_profile)#连接
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("http://58.240.51.118/?ssid=school")
driver.refresh()
driver.find_element_by_xpath('//*[@id="UserName"]').send_keys(mypassword3) #然而找不到这个元素。。。。
driver.find_element_by_xpath('//*[@id="PassWord"]').send_keys(mypassword3)
driver.implicitly_wait(5)
driver.find_element_by_xpath('//*[@id="logonbtn"]').click()
driver.implicitly_wait(10)
def ConnectNuaa():
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.disconnect()#断开网卡连接
time.sleep(3)#缓冲3秒
profile = pywifi.Profile()#配置文件
profile.ssid = "nuaa.portal"#wifi名称
profile.auth = pywifi.const.AUTH_ALG_OPEN#需要密码
profile.akm.append(pywifi.const.AKM_TYPE_NONE)#加密类型
profile.cipher = pywifi.const.CIPHER_TYPE_NONE#加密单元
iface.remove_all_network_profiles()#删除其他配置文件
tmp_profile = iface.add_network_profile(profile)#加载配置文件
iface.connect(tmp_profile)#连接
time.sleep(5)
driver = webdriver.Chrome()
driver.get("http://202.119.65.214/iPortal/index.htm#!/login")
driver.refresh()
driver.find_element_by_css_selector("input[name = 'username']").send_keys(myusername2)
driver.find_element_by_css_selector("input[name = 'password']").send_keys(mypassword2)
driver.implicitly_wait(5)
driver.find_element_by_xpath('//*[@id="btnLogout"]').click()
driver.implicitly_wait(10)
time.sleep(5)
driver.get("http://202.119.65.214/iPortal/index.htm#!/login")
driver.refresh()
driver.find_element_by_css_selector("input[name = 'username']").send_keys(myusername2)
driver.find_element_by_css_selector("input[name = 'password']").send_keys(mypassword2)
driver.implicitly_wait(5)
driver.find_element_by_xpath('//*[@id="btnLogin1"]').click()
driver.implicitly_wait(10)
time.sleep(5)
driver.quit()
#--------ping一下网络,检查是否联网-----
ConnectNuaa()
exit_code = os.system('ping web.jingoal.com')
if exit_code:
print("连接失败")
else:
print("连接成功")
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("https://web.jingoal.com")
driver.find_element_by_css_selector("input[name = 'username']").send_keys(myusername1)
time.sleep(1)
driver.find_element_by_css_selector("input[name = 'password']").send_keys(mypassword1)
time.sleep(1)
driver.find_element_by_css_selector("a[submit-click = 'submitLogin()']").click()
time.sleep(3)
driver.find_element_by_css_selector("span[class = 'clockBtn']").click()
time.sleep(3)
driver.quit()