Open www. 5 l eta. Com website, if already carried out by a user login name, then first Log.
To log the site is generally as follows: ( 1 ) the "Login" button in the top right corner. ( 2 ) to enter the account. ( 3 ) re-enter the password, and then click "Login" button. Now we want to use Python program that automatically log on completion of the above operations 51 CTO website.
Open 51CTO site via Python, after automatically enter the account password and click "Login" button, so
Complete 51 automatically log CTO website.
from time import sleep from selenium import webdriver url = 'http://www.51cto.com/' browser = webdriver.Chrome() browser.maximize_window browser.get(url)
browser.find_element_by_xpath('//*[@id="login_status"]/a[1]').click() #获取“登录”元素 broser.find_element_by_xpath('//*[@id="loginform-username"]').clear()#清空输入框 browser.find_element_by_xpath('//*[@id="loginform-username"]').send_keys('oomms') #填写用户名 broser.find_element_by_xpath('//*[@id="loginform-password"]').clear() #清空输入框 browser.find_element_by_xpath('//*[@id="loginform-password"]').send_keys('abc123') #填写密码 sleep(3) #加入等待 browser.find_element_by_xpath('//*[@id="login-form"]/div[3]/input').click() #单击“登录”按钮