使用selenium实现自动登录南通大学校园网

使用selenium实现自动登录南通大学校园网

使用selenium模拟登录校园网

准备事项

python环境,selenium包,pyinstaller包,相应的浏览器驱动

源码

# -*- coding: UTF-8 -*-
'''
@File: netConnect.py
@IDE: PyCharm
@Author: yuchun
@Date: 2021/11/3 13:37
'''
import sys
import time
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

broswer = webdriver.Edge(executable_path="C:\msedgedriver.exe")#浏览器驱动,我的是edge浏览器驱动
broswer.get('http://210.29.79.141/?isReback=1')#校园网网址

#time.sleep(1) 要是网页加载慢不能用可以试着加上这句代码,等待1s
try:
    webChoser = broswer.find_element(By.XPATH, '//*[@id="edit_body"]/div[2]/div[5]/span[3]/input')
    broswer.execute_script("arguments[0].click();", webChoser)
except Exception:
    broswer.quit()
    sys.exit()

userName = broswer.find_element(By.XPATH, '//*[@id="edit_body"]/div[2]/div[2]/div/div[2]/div[1]/div/form/input[3]')
userName.send_keys('xxxx')#填入你的账号

password = broswer.find_element(By.XPATH, '//*[@id="edit_body"]/div[2]/div[2]/div/div[2]/div[1]/div/form/input[4]')
password.send_keys('xxx')#填入你的密码

startBox = broswer.find_element(By.XPATH, '//*[@id="edit_body"]/div[2]/div[2]/div/div[2]/div[1]/div/form/input[2]')
broswer.execute_script("arguments[0].click();", startBox)

broswer.quit()#关闭浏览器

尝试过程中发现两个input虽然能定位但是click失败,应该是有什么别的元素在上面,用了broswer.execute_script("arguments[0].click();", startBox)这句实现点击操作

浏览器驱动地址

edge浏览器驱动

生成可执行exe文件

安装pyinstaller包

pip install pyinstaller

注意要先切到文件路径

在命令行输入

pyinstaller -F -w netConnect.py

成功后可以找到dist文件夹,里面有生成的exe文件

image-20211103223202472

到这里点击exe文件就已经可用使用了

生成脚本文件

新建txt文件,复制代码,修改路径为你生成的python的exe文件路径,保存,修改后缀为.bat

@echo off
if "%1" == "yes" goto begin
mshta vbscript:createobject("wscript.shell").run("cmd /c C:\netConnect.exe",0)(window.close)&&exit
:begin

image-20211103223613579

开机自启动

将bat文件放入开机启动文件夹

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

image-20211103223901426

完成

效果:开机自启动还没有qq自启动快,有点不行==

参考

Pycharm生成可执行文件.exe

开机自动运行exe - 殇之弑梦 - 博客园 (cnblogs.com)

posted @   YuChun_9293  阅读(446)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示