CSDN自动签到程序自动签到程序
2020年04月08日
虽然程序才20几行,但包括配置服务器环境什么的,前前后后也写了好几天
PS:程序运行于ubuntu18.04的阿里云服务器上(有图形化界面,且安装了Chrome,ChromeDriver),最后面附有windows版程序
签到的思路签到的思路
csdn用selenium打开的话,是不能用账号密码实现自动登录的,因为会有一个滑动验证码,
我们手动操作都验证不过的那种,所以不能用账号密码登录,那么只能我们先登录,让浏览器记住我们登录的状态
(这样也就隔绝批量登录签到的想法了,但用于个人签到还是没问题的,话说我也只有一个账号)。
如果用webdriver.Chrome()直接打开,浏览器是没有记住我们的登陆状态的,
要用google-chrome --remote-debugging-port=3353这种方式,然后再和我们的selenium进行对接,
再然后跳到签到的页面,签到的按钮在源代码中是个div块,没法直接点击,可以获取其坐标,模拟鼠标点击其中间位置完成签到,关闭浏览器,搞定。
最后弄个定时签到,如果用ubuntu自带的crontab自动签到,会出现比较多问题,,,有兴趣再自己尝试吧
我直接在代码里用apscheduler实现定时的功能。
程序代码程序代码
import subprocess
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from apscheduler.schedulers.background import BackgroundScheduler
def check_in():
p = subprocess.Popen(["google-chrome","--remote-debugging-port=3353"])
print('等待浏览器打开完毕...')
time.sleep(5)
options = webdriver.ChromeOptions()
options.debugger_address = "127.0.0.1:3353"
browser = webdriver.Chrome(options=options)
browser.get('https://i.csdn.net/#/uc/reward')
check_in = browser.find_element_by_xpath("//div[@class='handle_box to_sign']")
ActionChains(browser).move_by_offset(check_in.location['x']+check_in.size['width']/2, check_in.location['y']+check_in.size['height']/2).click().perform()
time.sleep(2)
p.kill()
if __name__ == '__main__':
scheduler = BackgroundScheduler()
scheduler.add_job(check_in, 'cron', hour='4',minute='0')
scheduler.start()
while True:
time.sleep(999)
后台运行后台运行
nohup python -u /home/rrr/PycharmProjects/ubuntu/CSDN/check_in.py >> /home/rrr/Desktop/log 2>&1 &
这样每天晚上的4点就会进行自动签到了。
评论0
最新资源