Python-selenium的安装及测试

1,安装库

pip install selenium

2,驱动下载

注意:

谷歌驱动一定要与电脑安装的谷歌版本一致

查看方式:

浏览器->设置->关于chrome

下载链接 https://chromedriver.storage.googleapis.com/index.html

3,修改环境变量

这里就不再赘述了

4,测试

from selenium import webdriver

# 设置本地安装目录
#若安装在C:\Program Files (x86)\Google\Chrome\Application,即C:\Program Files (x86)下不用明确位置
option = webdriver.ChromeOptions()
option.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'

#driver = webdriver.Chrome(r'd:\xxx\chromedriver.exe')  未将驱动设置至环境变量的可手动指定
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
print(driver.page_source)
driver.close()

5,效果展示

posted @ 2020-11-10 12:45  lifelikeplay  阅读(127)  评论(0编辑  收藏  举报