import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
脚本自动登录该网页
driver = webdriver.Chrome()
将健康表的地址copy过来就行
driver.get(“你的健康表地址”)
time.sleep(2)
print(“开始点击----立即登录”)
第一次点击登录跳转
driver.find_element_by_xpath(’//*[@id=“header-login-btn”]’).click()
time.sleep(5)
print(“开始点击快速登录”)
# selenium判断元素是否可以点击或者处理
element = driver.find_element_by_id(“img_out_191736586”)
element = driver.find_element_by_xpath(’//*[@id=“img_out_191733686”]’)
bianji = element.is_enabled() #是否可以编辑,或者按钮是否可以点击
xinashi = element.is_displayed() #:判断元素是否显示
xunazhong = element.is_selected() #:判断元素是否选中状态
print(bianji,xinashi,xunazhong)
element.click()
想了想为啥定位不到那个快速登录元素,原来html知识不够,切进iframe
driver.switch_to.frame(0) # 1.用frame的index来定位,第一个是0
driver.switch_to.frame(“frame1”) # 2.用id来定位
driver.switch_to.frame(“myframe”) # 3.用name来定位
driver.switch_to.frame(driver.find_element_by_tag_name(“iframe”)) # 4.用WebElement对象来定位
快捷登录
driver.find_element_by_xpath(’//*[@id=“img_out_1917336586”]’).click()
driver.find_elements_by_class_name(‘img_out_focus’)[0].click()
time.sleep(15)
print(“点击大数据人工智能一班SHEET”)
driver.find_elements_by_class_name(“sheet-tab-name”)[2].click()
driver.find_element_by_xpath(’//*[@id=“sheetbar”]/div[2]/div[3]/div/div[4]/span’).click()
time.sleep(3)
print(“开始点击更多”)
driver.find_element_by_xpath(’//*[@id=“toobarMoreButton”]/div/div/div[1]’).click()
driver.find_element_by_class_name(“toolbar-menu-button-more toolbar-inline-block”).click()
time.sleep(10)
print(“点击搜索”)
driver.find_elements_by_xpath(’//*[@id=“sheet-search-button”]/div/div/div’)[1].click()
time.sleep(3)
print(“开始点击搜索框”)
getinput = driver.find_element_by_xpath(’//*[@id=“search-panel-input”]’)
getinput.send_keys(“北极熊”)
time.sleep(2)
print(“已获取该位置” + getinput.location)
time.sleep(2)
Key.tab选择,Kys.enter确定结束
driver.find_element_by_id(‘alloy-simple-text-editor’).click()
driver.find_element_by_id(‘alloy-simple-text-editor’).send_keys("")http://www.yezidianjing.com/
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id(‘alloy-simple-text-editor’).click()
driver.find_element_by_id(‘alloy-simple-text-editor’).send_keys(“是”)
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id(‘alloy-simple-text-editor’).click()
driver.find_element_by_id(‘alloy-simple-text-editor’).send_keys(“是”)
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id(‘alloy-simple-text-editor’).click()
driver.find_element_by_id(‘alloy-simple-text-editor’).send_keys(“否”)http://yes-esports.com/
ActionChains(driver).key_down(Keys.TAB).perform()
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id(‘alloy-simple-text-editor’).click()
driver.find_element_by_id(‘alloy-simple-text-editor’).send_keys(“否”)
ActionChains(driver).key_down(Keys.TAB).perform()
driver.find_element_by_id(‘alloy-simple-text-editor’).click()
driver.find_element_by_id(‘alloy-simple-text-editor’).send_keys(“填写你的地址”)
driver.find_element_by_id(‘alloy-simple-text-editor’).send_keys(Keys.ENTER)
time.sleep(1)