option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument(
'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')
option.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=option)
driver.get(url)
element = driver.find_elements(By.CLASS_NAME, "tableDiv")
element1 = driver.find_elements(By.XPATH,
"/html/body/div[3]/div[0]/div[0]/div[0]/div[1]/div[0]/table/tbody/tr[2]/td[1]/a")
element3 = driver.find_elements(By.XPATH, '/html/body/div[3]/div[0]/div[0]/div[0]/h1')
不论用classname,还是XPATH,列表都为空
只要在driver.get(url)下加上下面的代码就可以获取到元素了
time.sleep(5)