1、下载Python http://www.python.org/ (百度云盘python-2.7.9.msi)
2、安装python(默认路径即可),并添加两个环境变量(右击计算机->属性->高级系统设置->环境变量->path,,输入c:\Python27;c:\Python27\Scripts)
//Scripts的目录其实是在pip安装了setuptools后生成的
3、下载pip https://pip.pypa.io/en/latest/installing.html ,无法下载的话打开文件,另存代码文件到本地也行,比如保存到f:\get-pip.py(百度云盘get-pip.py)
4、cmd进入命令行,路径切换到f盘,运行python get-pip.gy,(如果还提示python不是内部或外部命令,可以运行 set PATH=%PATH%;C:\Python27)等待自动完成setuptools安装(目的在于实现selenium使用pip命令进行安装)
5、在命令中切换到c:\Python27\Scripts的路径下,运行pip install -U selenium,等待自动完成selenium安装
6、在C盘目录下,创建文件test.py,代码如下:
from selenium import webdriver
browser=webdriver.Firefox()
browser.get("http://www.bozhong.com")
7、打开CMD,运行python c:\test.py,看到自动打开了firefox浏览器和进入播种网即证明上述步骤均正确
具体CMD运行命令(百度云盘python+seleniumcmd.txt)
PS:
如果使用chrome,
需先将chromedriver.exe拷贝到/python27/scripts 下并设置系统变量path,再将代码部分的browser=webdriver.Firefox() 替换为
options= webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
driver = webdriver.Chrome(options)
driver.get("http://you.8684.com")