csdn automatic check-in

csdn automatic sign-in applet

One, python+selenium development

by Tansty

github address: https://github.com/Tansty/CSDN-signup

gitte address: https://gitee.com/tansty/CSDN-signup




1. Login page

(1) First enter the official website

Insert picture description here




(2) Click to log in
Insert picture description here



2. Perform login operations

(1) First, you need to click the account password to log in
Insert picture description here

Construct statement to find elements

driver.find_element_by_link_text("账号密码登录").click()


(2) Enter the user name and password

Insert picture description here




(3) Review the elements

username:

Insert picture description here

password:

Insert picture description here

Construct the corresponding statement and use the css selector to select

driver.find_element_by_css_selector("[placeholder='手机号/邮箱/用户名']").send_keys(user)
driver.find_element_by_css_selector("[placeholder='密码']").send_keys(password)

Successfully input




(4) Click the login button

Insert picture description here

driver.find_element_by_css_selector("button").click()

Click to enter

Insert picture description here



3. Perform check-in operations

(1) It is found here that clicking on the avatar will jump to the personal center, and directly construct the function to visit the new web page

new_window='window.open("{}")'.format("https://i.csdn.net/#/uc/profile")#js函数,此方法适用于所有的浏览器
driver.execute_script(new_window)

Successfully entered

Insert picture description here




(2) Jump to the sign-in page

I found here that the web link of each button will be different, so I directly use js to jump to the new web page

new_window = 'window.open("{}")'.format("https://i.csdn.net/#/uc/reward")  # js函数,此方法适用于所有的浏览器
driver.execute_script(new_window)


(3) Complete sign-in

Insert picture description here
Insert picture description here

After experiments, it is found that the class attributes of the sign-in and the completed sign-in are different

Not checked in is: handle_box to_sign
checked in is completed: handle_box has_sign
can be drawn is: handle_box to_reward
construction code

		try:
            elem=driver.find_element_by_xpath("//div[@class='handle_box has_sign']")
        except:
            print("您有可能还未签到或可以抽奖")
        else:
            messagebox.showinfo("错误", "您已经签到过了")
            driver.quit()
            sys.exit(1)
        #如果已经完成签到就退出

        try:
            elem=driver.find_element_by_xpath("//div[@class='handle_box to_reward']")
        except:
            print("您还未签到")
        else:
            messagebox.showinfo("恭喜", "您可以去抽奖了")
            driver.quit()
            sys.exit(1)

        #提示可以抽奖
        try:
            elem=driver.find_element_by_xpath("//div[@class='handle_box to_sign']")
        except:
            messagebox.showinfo("错误", "没有找到对应的元素")
            driver.quit()
            sys.exit(1)
        else:
            elem.click()

Sign in successfully



2. Summary of corresponding knowledge points

1. Method of selecting elements

find_element_by_class_name: locate according to class

find_element_by_css_selector: According to css positioning

find_element_by_id: locate according to id

find_element_by_link_text: locate according to the text of the link

find_element_by_name: locate based on node name

find_element_by_partial_link_text: locate according to the text of the link, as long as it is included in the entire text

find_element_by_tag_name: locate by tag

find_element_by_xpath: Use Xpath to locate

PS: Changing element to elements will locate all eligible elements and return a List

比如:find_elements_by_class_name

What is returned is the web_element object



2. Browser window switching

If you need to switch the browser window to jump to a new webpage, otherwise he still searches on the original webpage and will report an error

for handle in driver.window_handles:
    driver.switch_to.window(handle)
    if "个人" in driver.title:
        break

Back to the original

# mainWindow变量保存当前窗口的句柄

mainWindow = wd.current_window_handle

Here is to save the handle of the current webpage, so that you can return later



3. js statement execution

new_window = 'window.open({}")'.format("https://i.csdn.net/#/uc/reward")  # js函数,此方法适用于所有的浏览器
driver.execute_script(new_window)

4.tkinter

The method adopted in this project:

 def set_init_window(self):
        self.init_window_name.title("CSDN自动签到")  #标题
        self.init_window_name.geometry()   #设置窗口大小,设置窗口位置
        self.init_label=Label(self.init_window_name,text="账号: ")
        self.init_label.grid()#x=0,y=0
        self.user=Entry(self.init_window_name)   #创建输入框
        self.user.grid(row=0,column=1)
        self.init_label2=Label(self.init_window_name,text="密码: ")
        self.init_label2.grid(row=1,column=0)
        self.password=Entry(self.init_window_name)
        self.password.grid(row=1,column=1)
        self.w=Button(text="签到", bg="lightblue", width=10,command=self.driver)
        self.w.grid()

The specific use of tk library: tkinter


Copyright statement: This article is the original article of the blogger and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting. Link to this article: https://blog.csdn.net/tansty_zh/article/details/108081090

Guess you like

Origin blog.csdn.net/tansty_zh/article/details/108081090