Python Selenium打开谷歌浏览器

                                                        Python Selenium打开谷歌浏览器
                        
注、windows下操作
1、电脑要有谷歌浏览器
    1)、确认谷歌版本
        谷歌图标->鼠标右键->打开文件所在的位置->第一个目录就是谷歌的版本(66.0.3359.181)我这里的是66版本的。
    2)、根据对应的谷歌版本下载谷歌驱动 chromedriver.exe
        谷歌驱动下载地址:[ http://chromedriver.storage.googleapis.com/index.html ]
        找到自己版本对应的谷歌驱动版本,我的谷歌对应的版本是 [ 2.37 ]
        下载 [     chromedriver_win32.zip ] 这个压缩包
        解压出来的文件是 [ chromedriver.exe ]
        把这个 .exe 文件放到 [ C:\Program Files (x86)\Google\Chrome\Application ] 这个目录下
        也就是 chrome.exe的同级目录
2、python代码:
    1)、操作浏览器python需要安装的包 [ selenium ]
        pip安装
            pip install selenium
    2)、打开浏览器的代码
        from selenium import webdriver
        import os

        chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe'
        os.environ['webdriver.chrome.driver'] = chrome_path     #设置系统环境变量
        drive = webdriver.Chrome(chrome_path)  #打开谷歌浏览器

        drive.get( 'https://www.baidu.com' )   #打开一个网址
        #driver.quit() #退出浏览器

猜你喜欢

转载自blog.csdn.net/qq_36025814/article/details/80432866