【python3】Mac下selenium3+chrome驱动+python3

环境: python3.6.4  seleinum3.11

事先准备好python3  环境、安装谷歌浏览器

1 安装seleinum

pip3 install selenium

2 安装chrome驱动

下载最新版mac chrome驱动(需FQ) , 

链接地址:https://sites.google.com/a/chromium.org/chromedriver/downloads , 按照箭头所指 ,点击进去即可

3 配置: 

 把下载的压缩包解压,并通过命令行 把 chromedriver 移动到 /usr/local/bin 目录

mv chromedriver  /usr/local/bin

4 测试脚本:

# coding=utf-8
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
driver.find_element_by_id('kw').send_keys('selenium')
driver.find_element_by_id('su').click()

 这时候,会自动打开谷歌并进行搜索

番外篇:

运行过程中遇到的错误:

1 chromedriver executable needs to be in PATH

   错误原因, 未把 chromedriver 移动到 /usr/local/bin 目录

2 unknown error: call function result missing 'value'

   错误原因: chromedriver 不是最新的,前去官网下载最新的,即可

猜你喜欢

转载自www.cnblogs.com/richerdyoung/p/8856013.html