from selenium import webdriver
import time
class Douban:
def __init__(self):
self.driver = webdriver.Chrome()
def login(self, url):
"""
登录豆瓣网,完成用户名和密码的校验
:param url:豆瓣网登录的网址
:return:
"""
self.driver.get(url=url)
self.driver.implicitly_wait(10)
self.driver.switch_to.frame(self.driver.find_elements_by_tag_name('iframe')[0])
accountlogin = self.driver.find_element_by_xpath('//ul[@class="tab-start"]/li[2]')
accountlogin.click()
username = self.driver.find_element_by_id('username')
username.clear()
username.send_keys("**********")
password = self.driver.find_element_by_name('password')
password.clear()
password.send_keys("*******")
login_button = self.driver.find_element_by_class_name('account-form-field-submit ')
login_button.click()
if __name__ == "__main__":
douban = Douban()
url = 'https://www.douban.com/'
douban.login(url=url)