当前位置:网站首页>CSDN auto sign in

CSDN auto sign in

2022-06-24 01:11:00 ruochen

#csdn Automatic check in

csdn Automatic check-in applet

One 、python+selenium Development

by Tansty

github Address :

gitte Address :

1. The login page

(1) First enter the official website

<img src="https://img-blog.csdnimg.cn/20200818163240304.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RhbnN0eV96aA==,size_16,color_FFFFFF,t_70#pic_center" alt=" Insert picture description here "> (2) Click login <img src="https://img-blog.csdnimg.cn/20200818163307974.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RhbnN0eV96aA==,size_16,color_FFFFFF,t_70#pic_center" alt=" Insert picture description here ">

2. Log in

(1) First, you need to click the account and password to log in <img src="https://img-blog.csdnimg.cn/20200818163411610.png#pic_center" alt=" Insert picture description here ">

Construct statements to find elements

driver.find_element_by_link_text(" Account password login ").click()

<img src="https://img-blog.csdnimg.cn/20200818163506754.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RhbnN0eV96aA==,size_16,color_FFFFFF,t_70#pic_center" alt=" Insert picture description here ">

user name :

<img src="https://img-blog.csdnimg.cn/20200818163520241.png#pic_center" alt=" Insert picture description here ">

password :

<img src="https://img-blog.csdnimg.cn/20200818163536872.png#pic_center" alt=" Insert picture description here ">

Construct the corresponding statement , Use css Select with the selector

driver.find_element_by_css_selector("[placeholder=' cell-phone number / mailbox / user name ']").send_keys(user)
driver.find_element_by_css_selector("[placeholder=' password ']").send_keys(password)

Successfully entered (4) Click the login button

<img src="https://img-blog.csdnimg.cn/20200818163555584.png#pic_center" alt=" Insert picture description here ">

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

Click to go to

<img src="https://img-blog.csdnimg.cn/20200818163609117.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RhbnN0eV96aA==,size_16,color_FFFFFF,t_70#pic_center" alt=" Insert picture description here ">

3. Check in

(1) It is found here that clicking on the avatar will jump to the personal Center , Direct constructor to access new web pages

new_window='window.open("{}")'.format("https://i.csdn.net/#/uc/profile")#js function , This method is applicable to all browsers 
driver.execute_script(new_window)

Successful entry

<img src="https://img-blog.csdnimg.cn/202008181636348.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RhbnN0eV96aA==,size_16,color_FFFFFF,t_70#pic_center" alt=" Insert picture description here "> (2) Jump to the check-in page

I found here that the web links of each button will be different , So I just use js Jump to a new page

new_window = 'window.open("{}")'.format("https://i.csdn.net/#/uc/reward")  # js function , This method is applicable to all browsers 
driver.execute_script(new_window)

<img src="https://img-blog.csdnimg.cn/20200818163723581.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RhbnN0eV96aA==,size_16,color_FFFFFF,t_70#pic_center" alt=" Insert picture description here "> <img src="https://img-blog.csdnimg.cn/20200818163743948.png#pic_center" alt=" Insert picture description here ">

After the experiment, it is found that signing in and completing signing in class Properties are different

No sign in yes :handle_box to_sign The completion of check-in is :handle_box has_sign The lucky draw is :handle_box to_reward Construction code

		try:
            elem=driver.find_element_by_xpath("//div[@class='handle_box has_sign']")
        except:
            print(" You may not have signed in yet or you can draw a lottery ")
        else:
            messagebox.showinfo(" error ", " You have signed in ")
            driver.quit()
            sys.exit(1)
        # If you have completed the check-in, exit 

        try:
            elem=driver.find_element_by_xpath("//div[@class='handle_box to_reward']")
        except:
            print(" You haven't signed in yet ")
        else:
            messagebox.showinfo(" Congratulations ", " You can go to the lucky draw ")
            driver.quit()
            sys.exit(1)

        # Tips can draw 
        try:
            elem=driver.find_element_by_xpath("//div[@class='handle_box to_sign']")
        except:
            messagebox.showinfo(" error ", " No corresponding element found ")
            driver.quit()
            sys.exit(1)
        else:
            elem.click()

Check in completed successfully

Two 、 Summary of corresponding knowledge points

1. How to select elements

find_element_by_class_name: according to class location

find_element_by_css_selector: according to css location

find_element_by_id: according to id location

find_element_by_link_text: Locate... According to the text of the link

find_element_by_name: Locate by node name

find_element_by_partial_link_text: Locate... According to the text of the link , Just include it in the whole text

find_element_by_tag_name: adopt tag location

find_element_by_xpath: Use Xpath Positioning

PS: hold element Change it to elements All eligible elements will be located , Return to one List

such as :find_elements_by_class_name

The return is web_element object

2. Browser window switch

If you jump to a new web page, you need to switch the browser window , Otherwise, he would still look for it on the original web page , Will report a mistake

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

Go back to the original

# mainWindow Variable holds the handle of the current window 

mainWindow = wd.current_window_handle

Here is to save the current web page first handle, Convenient return

3.js Execution of statements

new_window = 'window.open({}")'.format("https://i.csdn.net/#/uc/reward")  # js function , This method is applicable to all browsers 
driver.execute_script(new_window)

4.tkinter

The method adopted in this project :

 def set_init_window(self):
        self.init_window_name.title("CSDN Automatic check in ")  # title 
        self.init_window_name.geometry()   # Set window size , Set the window position 
        self.init_label=Label(self.init_window_name,text=" account number : ")
        self.init_label.grid()#x=0,y=0
        self.user=Entry(self.init_window_name)   # Create input box 
        self.user.grid(row=0,column=1)
        self.init_label2=Label(self.init_window_name,text=" password : ")
        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=" Sign in ", bg="lightblue", width=10,command=self.driver)
        self.w.grid()

tk Specific use of Library :

原网站

版权声明
本文为[ruochen]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211120085508863c.html

随机推荐