11.Selenium+Python案例--百度
一.具体代码实现
from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.select import Select import time driver = webdriver.Ie() driver.maximize_window() #浏览器窗口最大化 driver.get("https://www.baidu.com/") driver.implicitly_wait(10) setting = driver.find_element_by_link_text("设置") ActionChains(driver).move_to_element(setting).perform() driver.find_element_by_link_text("搜索设置").click() driver.implicitly_wait(10) selector = driver.find_element_by_name("NR") Select(selector).select_by_index(2) time.sleep(3) driver.find_element_by_xpath('//*[@id="gxszButton"]/a[1]').click() time.sleep(3) driver.switch_to.alert.accept() driver.find_element_by_id("kw").send_keys("python") driver.find_element_by_id("su").click()