本文共 643 字,大约阅读时间需要 2 分钟。
安装及使用的中文文档可以在这里找到
# pip install selenium
selenium3.x以上需要浏览器驱动,到这里下载相应驱动,
解压驱动到/usr/bin
或/usr/local/bin
运行下面代码,测试是否能正常使用
from selenium import webdriverfrom selenium.webdriver.common.keys import Keysdriver = webdriver.Firefox()driver.get('https://www.baidu.com')assert 'Python' in driver.titleelem = driver.find_element_by_name('q')elem.send_keys('pycon')elem.send_keys(Keys.RETURN)assert 'No results found.' not in driver.page_source# driver.close()
No such file or directory: 'geckodriver'
没有装上驱动,或没有放到指定位置
Message: can not connect to the service geckodriver
可能是没有localhost,打开/etc/hosts
,看里面有没有这样一句
127.0.0.1 localhost
没有就加上 转载地址:http://qopjz.baihongyu.com/