1 安装环境

学习教程:
http://www.python3.vip
http://www.testclass.net/selenium_python/

1、安装python和selenium
下载python安装后,添加好环境变量。
本地安装了python2和python3两个版本,其中修改了python3.exe名改为python.exe。

打开cmd,切换至python的安装目录下,执行 pip install selenium,即可实现安装selenium。

注意,安装selenium后不要再修改python.exe的文件名了,否则会导致pip无法使用。
参考:https://blog.csdn.net/qq_42040086/article/details/103554988?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-8.pc_relevant_is_cache&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-8.pc_relevant_is_cache

2、Chrome驱动下载
查看自己Chrome浏览器的版本,把对应版本的浏览器驱动下载,放在某个路径下解压。该路径之后要用。如g:webdriverchromedriver.exe 。
chrome驱动器下载:
https://chromedriver.storage.googleapis.com/index.html
https://npm.taobao.org/mirrors/chromedriver/

3、实验
from selenium import webdriver
--创建 WebDriver 对象,指明使用chrome浏览器驱动
wd = webdriver.Chrome(r'g:webdriverchromedriver.exe')
--调用WebDriver 对象的get方法 可以让浏览器打开指定网址
wd.get('https://www.baidu.com')

即初步实现了自动打开浏览器和输入网址。

原文地址:https://www.cnblogs.com/Tsingje/p/13974245.html