1.下载chrome/firefox驱动,对应相应版本的浏览器
把下载的浏览器驱动放在python目录下之后(前提python目录是环境变量path下的,我们之前放的是c盘的根目录)
2.打开pycharm新建项目:
file--new project
![](https://upload-images.jianshu.io/upload_images/16945005-918cf134f7e1259f.png?imageMogr2/auto-orient/strip|imageView2/2/w/789)
3.新建python文件,右键工程新建:
![](https://upload-images.jianshu.io/upload_images/16945005-33f66a90a48cfc5e.png?imageMogr2/auto-orient/strip|imageView2/2/w/938)
4.工程下导入selenium
file--setting--project:WebAutoScript--project interpreter
![](https://upload-images.jianshu.io/upload_images/16945005-8668a5750962b709.png?imageMogr2/auto-orient/strip|imageView2/2/w/1023)
![](https://upload-images.jianshu.io/upload_images/16945005-2a33435a9712ad2a.png?imageMogr2/auto-orient/strip|imageView2/2/w/936)
5.编写脚本:
使用google chrome浏览器
from seleniumimport webdriver
driver=webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.quit()
使用firefox浏览器:
from seleniumimport webdriver
driver=webdriver.Firefox()
driver.get('https://www.baidu.com')
driver.quit()