配置webdriver环境

安装环境pip install selenium,提示 

Could not find a version that satisfies the requirement selenium (from versions: )

No matching distribution found for selenium,可把我担心了,百度了下没看到什么好的,再次去执行,就正常安装了,然而,安装的是3.0.1,当时没注意,

开始尝试

>>> from selenium import webdriver

>>> dr=webdriver.Firefox()

结果提示

selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH.

就继续百度,说这是selenium3需要额外驱动geckodriver,然后添加到环境变量。作为小白,看着资源都是2的,就降版本了(执行pip install selenium==2.53.0)。

if you specified a log_file in the FirefoxBinary constructor,check it for detail

搜了下,原因是selenium版本和Firefox版本不兼容,然后去装了官网45的Firefox,运行上面两个代码是正常的,

#-*- coding:utf-8 -*-

from selenium import webdriver

driver=webdriver.Firefox()

driver.get("https://www.baidu.com")

driver.find_element_by_id("kw").send_keys("Selenium")

driver.find_element_by_id("su").click()

driver.quit()

写到.py运行就提示plugin container for firefox

百度了下是插件问题,找了几个方法,免沙箱版flash的dll,试了下不行,就去找其他版本浏览器了,找到一个46.0的,用了,很好,新的开始啊。

总之最直接的就是换低版本适合的浏览器

文章来自:http://www.cnblogs.com/wenermao/p/6078999.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3