看到了一篇用设计器抢先打卡的文章,心血来潮,也写一个

这个就全部用代码来写。

通过 selenium 框架来实现自动打卡

导库

#!/usr/bin/env Python3
# -*- coding: utf-8 -*-
# @Software: PyCharm
# @virtualenv:workon
# @contact: contact information
# @Desc:Code descripton
__author__ = '未昔/AngelFate'
__date__ = '2019/9/7 22:10'
from selenium import webdriver
import time

import headers_ 

设置 属性

self.start_url = '*****************'
self.option = webdriver.ChromeOptions()
print(headers_.headers_())

self.driver = webdriver.Chrome(options=self.option)
self.driver.get(self.start_url)
self.driver.maximize_window()  
print(self.driver.title) 

登录论坛

html = self.driver.page_source  
print(html)

if '让我们放弃使用那些过时、不安全的浏览器吧' in html:
	print('浏览器版本较低!!!')
	self.driver.quit()

elif 'unlogin' in html:
	print('您未登录,请先登录!!!')
	self.driver.implicitly_wait(10)
	self.driver.find_element_by_xpath('*//a[@class="unlogin"]').click()

	self.driver.implicitly_wait(10)  # 隐形隐藏时间
	self.driver.find_element_by_xpath('*//input[@id="nameOrEmail"]').send_keys(账号)
	self.driver.find_element_by_xpath('*//input[@id="loginPassword"]').send_keys(密码)
	self.driver.find_element_by_xpath('*//button[@class="green"]').click()

	self.driver.implicitly_wait(10)  # 隐形隐藏时间
	time.sleep(3)
	# print(self.driver.page_source)

	if '工单' in self.driver.page_source:
		print('您已成功登录!!!')

		# 获取本页所有的文章
		time.sleep(2)
		node_list = self.driver.find_elements_by_xpath('*//a[@class="ft-a-title"]')
		print(node_list)
		for node in node_list:
			name = node.find_element_by_xpath('.//a[@class="ft-a-title"]').get_attribute('href')
			print(name)
		self.driver.quit()

	else:
		print('登录失败!!!')
		self.driver.quit()

此时,已经可以登录网站,并且获得所有的标题和链接了。至于每天要打卡的文章。这个部分吗,大家自己思考。。。要是标题改了就不好了。。。。

main 函数

 rpa = ISRPA()
    count = 0
    while True:
        try:
            rpa.rpa()
            print('执行{}次完毕!!'.format(count))
            count+=1
            time.sleep(10)
        except Exception as e:  
            print(e)