将下载的压缩包,放置到Chrome安装目录下
点击系统变量中的path,点击新增,并将chromeDriver的安装目复制填入后,点击确定。
from selenium import webdriver executable_path=Service(r"C:/Program Files/Google/Chrome/Application/chromedriver.exe") self.driver = webdriver.Chrome(service=executable_path) # 当前浏览器驱动对象
pip install selenium
pip install –upgrade selenium
'WebDriver' object has no attribute 'find_element_by_name'
from selenium.webdriver.common.by import By #导入by
module 'selenium.webdriver' has no attribute 'phantomjs'
卸载最新版本,安装2.48.0
Selenium 不再支持 PhantomJS 的解决办法
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://cnblogs.com/")
在使用 Selenium 操作 Chrome 浏览器时,有时 Chrome 浏览器窗口会在操作完成后立即关闭。这可能是因为代码中缺少类似 time.sleep(5) 这样的代码,导致程序无法等待操作完成后再关闭浏览器。