Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does python simulate users to sign in automatically?

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you about how python simulates users to sign in automatically. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Application scenario

1. The required environment selenium.

2. Install the simulation plug-in.

3. Browser plug-in chromedriver.exe downloads simulation from the Internet and clicks on the browser. You need to find the plug-in that suits your browser.

Download link: https://npm.taobao.org/mirrors/chromedriver/

4. After downloading, put the plug-in in the folder where Chrome.exe is located.

Example

Import timeimport datetimeimport randomfrom selenium import webdriver def morning_clockin (): # find the path of the plug-in and use it to drive the operation browser = webdriver.Chrome ('C:\ Program Files\ Google\ Chrome\ Application\ chromedriver.exe') # Select the URL that needs to sign in Fill in your check-in page browser.get ('https://www.baudu.login')# find the xpath of the email and password input box Enter the account password browser.find_element_by_xpath ('/ / * [@ id= "email"]') .send_keys ("724183***@qq.com") browser.find_element_by_xpath ('/ / * [@ id= "passwd"]') .send_keys ("zhan*") # in the corresponding location to find the xpath of the login button Click browser.find_element_by_xpath ('/ * [@ id= "login"]') .click () time.sleep (2) # to find the xpath of the check-in button, and simulate the check-in browser.find_element_by_xpath ('/ html/body/div [3] / div [7] / div/button') .click () if _ _ name__ = ='_ _ main__':# to get the week of the day Today = datetime.datetime.now (). Weekday () + 1 if (today% 7 = = 0) or (today% 7 = = 6): print ("Today is the {} day of the week" No need to sign in! ".format (datetime.datetime.now (). Weekday () + 1)) # sign in on weekdays else: # sign in in the morning-set a random number between 0 and 300 seconds print (datetime.datetime.now ()) random_time = random.randint (0 60) time.sleep (random_time) # sign in morning_clockin () print (datetime.datetime.now ()) Thank you for your reading! This is the end of the article on "how python simulates users to sign in automatically". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report