selenium python 百度网盘的登陆与退出
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium python 百度网盘的登陆与退出相关的知识,希望对你有一定的参考价值。
1 # -*- coding:utf-8 -*- 2 from selenium import webdriver 3 from selenium.webdriver.common.action_chains import ActionChains 4 from selenium.webdriver.support.ui import WebDriverWait 5 6 import time 7 8 driver = webdriver.Firefox(executable_path=‘/Users/huiliang/Downloads/geckodriver‘) 9 driver.get("http://pan.baidu.com/") 10 driver.implicitly_wait(10) 11 12 #登陆百度网盘 13 driver.find_element_by_xpath(‘//*[@id="login-middle"]/div/div[6]/div[2]/a‘).click() 14 driver.find_element_by_id(‘TANGRAM__PSP_4__userName‘).clear() 15 driver.find_element_by_id(‘TANGRAM__PSP_4__userName‘).send_keys(‘xxx‘) 16 driver.find_element_by_id(‘TANGRAM__PSP_4__password‘).clear() 17 driver.find_element_by_id(‘TANGRAM__PSP_4__password‘).send_keys(‘ooo‘) 18 driver.find_element_by_id(‘TANGRAM__PSP_4__submit‘).click() 19 20 #确认是否登陆成功 21 test = driver.find_element_by_xpath(‘//*[@id="dynamicLayout_0"]/div/div/dl/dd[2]/span/span[2]‘).text 22 print test 23 if test == ‘xxx‘: 24 print u‘登陆成功‘ 25 26 #退出百度网盘 27 ele = driver.find_element_by_xpath(‘//*[@id="dynamicLayout_0"]/div/div/dl/dd[2]/span/span[1]/i‘) 28 ActionChains(driver).move_to_element(ele).perform() 29 sub_ele = driver.find_element_by_link_text(u‘退出‘) 30 sub_ele.click() 31 ele_out = driver.find_element_by_id(‘_disk_id_4‘) 32 ele_out.click() 33 34 35 time.sleep(5) 36 driver.quit()
以上是关于selenium python 百度网盘的登陆与退出的主要内容,如果未能解决你的问题,请参考以下文章