自动签到脚本

自动签到脚本

#!/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()
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值