Python+Selenium(一)环境搭建

      Python+Selenium()环境搭建

1. Python下载安装

   进入Python官网下载,我使用的版本为Python3.4.6,按照安装向导的指引安装。

             

进入cmd验证:

            

2. 安装Selenium

找到Python安装的位置,打开CMDcd PythonScripts文件夹;通过pip命令安装Selenium

命令:pip install selenium

 

3. 安装FrieFox浏览器

   建议下载55以上的版本,低版本搭配Python3+Selenium会存在兼容性问题,导致无法正常使用。

   下载FireFox浏览器驱动:geckodriver.exe 并且将其存放到Python根目录下(与python.exe 同一目录)。

下载地址:https://github.com/mozilla/geckodriver/releases

4. 验证搭建的环境

1.启动cmd,进入命令窗口,输入Python

2.>>from selenium import webdriver;

3.>>driver = webdriver.Firefox();

4.>>driver.get(‘https://www.baidu.com’)

   

5. 安装Python IDE工具PyCharm

6. 搭建环境时遇到的坑

   6.1没有安装Firefox geckodriver

      解决:

        下载FireFox浏览器驱动:geckodriver.exe 并且将其存放到Python根目录下(与python.exe 同一目录)。

下载地址:https://github.com/mozilla/geckodriver/releases

   6.2Firefox浏览器与Selenium3.X版本不兼容。

       解决:

          更新浏览器到最新版本

猜你喜欢

转载自blog.csdn.net/sinat_40295209/article/details/79518318