1、安装Python35
官网:https://www.python.org/downloads/windows/
我安装的版本是v3.5.2,Windows系统
安装过程中记得勾选安装到环境的复选框:Add Python 3.5 to PATH,不然安装完成后还需要手动进行环境变量的配置。
2、下载selenium插件
在cmd中输入命令:python-m pip install selenium
*如果提示Python不是内部或外部命令,就需要将Python路径配置到环境变量去
3、新建一个txt文件,取名并修改后缀为test.py,将以下代码复制并保存:
from selenium import webdriver
import time
browser = webdriver.Firefox()
browser.get("http://www.baidu.com")
time.sleep(5)
browser.close()
4、执行Python文件
可直接双击test.py执行,更靠谱的方式还是在cmd中输入命令:python test.py
使用Firefox
如果这是第一次使用selenium,可能会报以下这个错误:
E:\python\selenium>python test.py
Traceback (most recent call last):
File "C:\Users\Python\Python35\lib\site-pac
kages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C