from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_experimental_option('useAutomationExtension', False)
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# 打开chrome浏览器
driver = webdriver.Chrome(options=option)
driver.get("https://www.baidu.com.cn")
"""元素定位"""
# 根据id获取元素
ele = driver.find_element_by_id("kw")
print(ele.get_attribute("class")) # 获取当前元素的属性
# 根据name获取元素
ele = driver.find_element_by_name("wd")
# 根据name获取元素
ele = driver.find_element_by_tag_name("input")
ele = driver.find_element_by_partial_link_text("新") # 根据超链接文本获取元素 可以模糊匹配
ele = driver.find_element_by_link_text("新闻") # 必须相等
driver.find_element_by_class_name() # 根据class name获取
driver.find_element_by_css_selector("input#kw.s_stt") # 根据css获取
driver.quit()