python实现网页自动签到功能
作者:娇兮心有之 时间:2024-01-03 00:13:14
本文实例为大家分享了python实现网页自动签到功能的具体代码,供大家参考,具体内容如下
第1步、环境准备(用的chrome浏览器)
1.安装selenium包
pip install selenium
2.下载chromedriver驱动;
找到符合自己浏览器版本的chromedriver驱动,下载解压后,将chromedriver.exe文件放到Python目录下的Scripts目录下,也可以添加环境变量到Path中;
第2步、Selenium脚本源码
比较简单,而且有详细注释就不一一说明了
# -*- coding: utf-8 -*-
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#myusername = "XXX"#登录账号
#mypassword = "XXX"#登录密码
driver = webdriver.Chrome() #模拟浏览器打开网站
driver.get("https://www.ctguqmx.com")
#driver.maximize_window() #将窗口最大化
try:
driver.find_element_by_xpath('/html/body/div[1]/div/div[4]/span/a[1]').click()#定位语句去源码中找
time.sleep(2)#延时加载
#找到登录框,输入账号密码
driver.find_element_by_xpath("//*[@id='aw-login-user-name']").send_keys("myusername")
driver.find_element_by_xpath("//*[@id='aw-login-user-password']").send_keys("mypassword")
#模拟点击登录
driver.find_element_by_xpath("//*[@id='login_submit']").click()
time.sleep(2)
#模拟登陆后点击签到界面
driver.find_element_by_xpath("/html/body/div[1]/div/div[5]/a").click()
time.sleep(2)
#模拟点击签到
driver.find_element_by_xpath("//*[@id='qd_button']").click()
time.sleep(2)
print("签到成功")
except:
print("签到失败")
driver.quit#退出去动
注:写完之后可以尝试运行代码,如果报错RROR:install_util.cc(597)] Unable to read registry value HKLM\SOFTWARE\Policies\Google\Chrome\MachineLevelUserCloudPolicyEnrollmentToken可以在注册列表中在提示路径下添加字符串值Chrome\MachineLevelUserCloudPolicyEnrollmentToken
第3步、添加Windows定时任务
1.我的电脑>右键管理>(左侧栏)任务计划程序>Microsoft>Windows>(右侧栏)创建任务(详见百度)
2.设置任务:
命名任务
设置触发器
设置操作
注意:该方法的前提是py后缀的脚本文件默认打开方式是python,可以先尝试一下,本人就是默认python打开,如果不行可以用下面方法设置默认打开方式:
1.win+R打开运行;
2.输入regedit,确定;
3.在打开的注册表中找到以下目录:
HKEY_CLASSES-ROOT->Python.file->shell->open->command
4.将该项的内容修改为:
“D:\Python\Python3.6.1\pythonw.exe” “D:\Python\Python3.6.1\Lib\idlelib\idle.pyw” -e “%1”
(将其中的路径修改为自己python的安装路径即可)
来源:https://blog.csdn.net/qq_40925239/article/details/83003413
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mysql中取字符串中的数字的语句
JavaScript静态的动态
Python列表推导式与生成器表达式用法示例
python通过pillow识别动态验证码的示例代码
![](https://img.aspxhome.com/file/2023/5/62295_0s.png)
利用Python实现自动工作汇报的脚本分享
![](https://img.aspxhome.com/file/2023/8/128498_0s.png)
Python PaddleGAN实现调整照片人物年龄
![](https://img.aspxhome.com/file/2023/2/90612_0s.png)
Anaconda使用IDLE的实现示例
![](https://img.aspxhome.com/file/2023/0/99650_0s.png)
Python学习之Django的管理界面代码示例
![](https://img.aspxhome.com/file/2023/2/98992_0s.png)
远程过程调用RPC基本概念及实现原理
![](https://img.aspxhome.com/file/2023/5/120545_0s.jpg)
Python linecache.getline()读取文件中特定一行的脚本
![](https://img.aspxhome.com/file/2023/5/67725_0s.gif)
php中的登陆login
GO语言包管理工具go mod以及包详解
![](https://img.aspxhome.com/file/2023/7/127377_0s.jpg)
Python使用装饰器模拟用户登陆验证功能示例
![](https://img.aspxhome.com/file/2023/7/114657_0s.png)
python中的多线程锁lock=threading.Lock()使用方式
解决Pycharm 导入其他文件夹源码的2种方法
python通过索引遍历列表的方法
C#如何在窗体程序中操作数据库数据
![](https://img.aspxhome.com/file/2023/4/87034_0s.png)
matlab画三维图像的示例代码(附demo)
![](https://img.aspxhome.com/file/2023/9/131869_0s.jpg)
python实现自动化群控的步骤
![](https://img.aspxhome.com/file/2023/1/105701_0s.png)