Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题

安装Python应该没什么好说的,我说说主要是安装selenium时遇到的问题。

问题清单:

1.’pip’ is not recognized as an internal or external command

2.Could not find a version that satisfies the requirement selenium (from versions…

3.driver = webdriver.Chrome()出的问题:Message: ‘chromedrive’ executable needs to be in…

4.启动chrome浏览器时的提示:you are using an unsupported command-line flag:…【这个我觉得解决的挺有意义,自我感觉不错~

1.’pip’ is not recognized as an internal or external command

这个问题一查才知道是我自己看漏安装配置忘了把Python下scripts文件夹的路径加进去了……真是失败,就不贴图了。大家找个详细点的安装指南就应该有说。

2.Could not find a version that satisfies the requirement selenium (from versions…

《Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题》 Could not find a version that satisfies the requirement selenium (from versions…

一查百度谷歌对于这个问题简直是众说纷纭,有的说是少装了依赖软件,有的说把selenium的具体版本号也一并写出来试试等等,最后查到一个贴时瞬间恍然大悟,于是分分钟解决了问题……☞http://python-china.org/t/652。【其实就是因为我之前用的公司内网,后来换了外网就好……

《Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题》 总之安装成功!开心!

3.driver = webdriver.Chrome()出的问题

《Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题》 Message: ‘chromedrive’ executable needs to be in PATH…

缺少chromedriver.exe,下载了放到Python的scripts目录下就好。

《Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题》 恩,写的测试小case还算成功启动~

4.Chrome提示:you are using an unsupported command-line flag: –ignore-certificate-errors. Stability and security will suffer.

《Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题》 you are using an unsupported command-line flag…

这个问题是因为chromedriver的版本与chrome浏览器版本不符合产生的,在网上查证后发现有两种解决方法。

①在代码里加上以下一段:

options = webdriver.ChromeOptions()

options.add_argument(“–test-type”)  

driver = webdriver.Chrome(chrome_options=options)

P.S. add_argument:读入命令行参数,该调用有多个参数。

ArgumentParser.add_argument(name or flags…[, action][, nargs][, const][, default][, type][, choices][, required][, help][, metavar][, dest])

type: 使用这个参数,转换输入参数的具体类型,这个参数可以关联到某个自定义的处理函数,这种函数通常用来检查值的范围,以及合法性。

总之这个是通过转换参数类型来让chrome浏览器取消提示,但是我觉得是个治标不治本的方法,所以我们继续进行下一种!

②更新chromedriver版本,使之与你当前的chrome浏览器版本相符即可。注意不要追求新而盲目使用最新的的chromedriver.exe。【因为我试过然后chrome浏览器打开后马上直接自己关闭了……

我们可以在https://sites.google.com/a/chromium.org/chromedriver/downloads下载和查看不同版本的chrome对应的chromedriver。鼓励大家多查看这个官方网站涨知识。

《Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题》 例子

下载好对应的chromedriver后将其放入scripts目录下即可。

《Python3&Selenium 安装&简单使用中出现的一些奇奇怪怪的问题》 完美!

参考:

python的argparse模块add_argument详解

http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=21633169&id=4387657

You are using an unsupported command-line flag: –ignore-certificate-errors. Stability and security will suffer

http://stackoverflow.com/questions/24442310/you-are-using-an-unsupported-command-line-flag-ignore-certificate-errors-sta

    原文作者:洛姆
    原文地址: https://www.jianshu.com/p/fd9c756f6846
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞