selenium简单食用 导入 1 2 3 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service
学会的方法–持续更新 设置渲染规则 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 op = webdriver.ChromeOptions() op.headless = True driver_path = Service(r'浏览器引擎的绝对路径' ) driver = webdriver.Chrome(service = driver_path, options = op) driver.get("" ) driver.implicitly_wait(10 ) vc = driver.find_element(By.XPATH, "//*[@class='']" ) vi = driver.find_element(By.ID, 'id name' ) vpic = vi.screenshot('保存路径' )
过网站自动化检测 没看明白,不过再设置渲染规则时加上这几句就可以过网站selenium检测,没有正在接受自动化测试的字了 1 2 3 4 5 6 7 8 9 10 11 op .add_experimental_option('excludeSwitch' , ['enable-automation' ]) op .add_experimental_option('useAutomationExtension' , False ) driver .execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument" , { "source" : """ Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) """ }) driver.implicitly_wait(10 )
参考资料 selenium超全教程(老版):https://zhuanlan.zhihu.com/p/343948620
https://zhuanlan.zhihu.com/p/521545291
去报错教程:https://blog.csdn.net/JBY2020/article/details/121909071
https://blog.csdn.net/m0_62298204/article/details/120802053
xpath路径表达式 https://juejin.cn/post/7135261141558788127#heading-5