解决find_element_by_id方法被弃用

  • 使用新版本的方法 find_element()

  • 使用的时候需要导入模块 from selenium.webdriver.common.by import By

属性定位方法 原定位方法find_element_by_* 推荐定位方法find_element()
xpath find_element_by_xpath(“//*[@id=‘search’]”) find_element(By.XPATH, “//*[@id=‘search’]”)
class_name find_element_by_class_name(“element_class_name”) find_element(By.CLASS_NAME, “element_class_name”)
id find_element_by_id(“element_id”) find_element(By.ID,“element_id”)
name find_element_by_name(“element_name”) find_element(By.NAME, “element_name”)
link_text find_element_by_link_text(“element_link_text”) find_element(By.LINK_TEXT,“element_link_text”)
css_selector find_element_by_css_selector(“element_css_selector”) find_element(By.CSS_SELECTOR, “element_css_selector”)
tag_name find_element_by_tag_name(“element_tag_name”) find_element(By.TAG_NAME, “element_tag_name”)
partial_link_text ind_element_by_partial_link_text(“element_partial_link_text”) find_element(By.PARTIAL_LINK_TEXT, “element_partial_link_text”)

你可能感兴趣的:(Python爬虫,selenium,vscode,python)