Edge Driver下载地址:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ 一般操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| from selenium import webdriver from time import sleep
from selenium.webdriver.common.keys import Keys
if __name__ == "__main__": browser = webdriver.Edge(executable_path='../../msedgedriver.exe') browser.get("https://xgpax.top/") title = browser.find_element_by_class_name('banner-title-inner') sleep(3) print(title.get_attribute("class"), title.text) browser.execute_script('window.scrollTo(0,document.body.clientHeight)') search = browser.find_element_by_xpath('//*[@id="leftbar_search_input"]') search.click() search.send_keys("转存") search.send_keys(Keys.ENTER) sleep(5) browser.quit()
|
iframe和windows操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| from selenium import webdriver from time import sleep
if __name__ == "__main__": brow = webdriver.Edge("../../msedgedriver.exe") brow.get("http://www.yhdongman.com/show/28217-31716-0.html") sleep(2) search = brow.find_element_by_css_selector("#bdcs-search-form-input") search.send_keys("shabi") iframe = brow.find_element_by_xpath('//*[@id="dm456_player"]/iframe') brow.switch_to.frame(iframe) iframe_img = brow.find_element_by_xpath('//*[@id="player"]') iframe_img.click() brow.switch_to.default_content() brow.find_element_by_xpath('/html/body/div[7]/div/a[1]').click() brow.switch_to.window(brow.window_handles[1]) brow.close() brow.switch_to.window(brow.window_handles[0]) sleep(2) brow.get("https://taobao.com") sleep(3) brow.get("https://baidu.com") sleep(5) brow.quit()
|
动作链操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| from selenium import webdriver from time import sleep
from selenium.webdriver import ActionChains
if __name__ == "__main__": edge = webdriver.Edge(executable_path="../../msedgedriver.exe") edge.get("https://xgpax.top/") edge.fullscreen_window() sleep(5) a = edge.find_element_by_xpath('//*[@id="post-340"]/header/div/a') action = ActionChains(edge) action.click_and_hold(a) for i in range(100): action.move_by_offset(0, 1) sleep(0.1) action.release()
|