安裝Python應(yīng)該沒什么好說的,我說說主要是安裝selenium時(shí)遇到的問題。
問題清單:
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瀏覽器時(shí)的提示:you are using an unsupported command-line flag:...【這個(gè)我覺得解決的挺有意義,自我感覺不錯(cuò)~
1.'pip' is not recognized as an internal or external command
這個(gè)問題一查才知道是我自己看漏安裝配置忘了把Python下scripts文件夾的路徑加進(jìn)去了……真是失敗,就不貼圖了。大家找個(gè)詳細(xì)點(diǎn)的安裝指南就應(yīng)該有說。
2.Could not find a version that satisfies the requirement selenium (from versions...
Could not find a version that satisfies the requirement selenium (from versions...
一查百度谷歌對于這個(gè)問題簡直是眾說紛紜,有的說是少裝了依賴軟件,有的說把selenium的具體版本號也一并寫出來試試等等,最后查到一個(gè)貼時(shí)瞬間恍然大悟,于是分分鐘解決了問題……?http://python-china.org/t/652。【其實(shí)就是因?yàn)槲抑坝玫墓緝?nèi)網(wǎng),后來換了外網(wǎng)就好……
總之安裝成功!開心!
3.driver = webdriver.Chrome()出的問題
Message: 'chromedrive' executable needs to be in PATH...
缺少chromedriver.exe,下載了放到Python的scripts目錄下就好。
恩,寫的測試小case還算成功啟動~
4.Chrome提示:you are using an unsupported command-line flag: --ignore-certificate-errors. Stability and security will suffer.
you are using an unsupported command-line flag...
這個(gè)問題是因?yàn)閏hromedriver的版本與chrome瀏覽器版本不符合產(chǎn)生的,在網(wǎng)上查證后發(fā)現(xiàn)有兩種解決方法。
①在代碼里加上以下一段:
options = webdriver.ChromeOptions()
options.add_argument("--test-type") ?
driver = webdriver.Chrome(chrome_options=options)
P.S. add_argument:讀入命令行參數(shù),該調(diào)用有多個(gè)參數(shù)。
ArgumentParser.add_argument(name or flags…[, action][, nargs][, const][, default][, type][, choices][, required][, help][, metavar][, dest])
type: 使用這個(gè)參數(shù),轉(zhuǎn)換輸入?yún)?shù)的具體類型,這個(gè)參數(shù)可以關(guān)聯(lián)到某個(gè)自定義的處理函數(shù),這種函數(shù)通常用來檢查值的范圍,以及合法性。
總之這個(gè)是通過轉(zhuǎn)換參數(shù)類型來讓chrome瀏覽器取消提示,但是我覺得是個(gè)治標(biāo)不治本的方法,所以我們繼續(xù)進(jìn)行下一種!
②更新chromedriver版本,使之與你當(dāng)前的chrome瀏覽器版本相符即可。注意不要追求新而盲目使用最新的的chromedriver.exe。【因?yàn)槲以囘^然后chrome瀏覽器打開后馬上直接自己關(guān)閉了……
我們可以在https://sites.google.com/a/chromium.org/chromedriver/downloads下載和查看不同版本的chrome對應(yīng)的chromedriver。鼓勵(lì)大家多查看這個(gè)官方網(wǎng)站漲知識。
例子
下載好對應(yīng)的chromedriver后將其放入scripts目錄下即可。
完美!
參考:
python的argparse模塊add_argument詳解:
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=21633169&id=4387657
http://stackoverflow.com/questions/24442310/you-are-using-an-unsupported-command-line-flag-ignore-certificate-errors-sta
作者:洛姆
鏈接:http://www.lxweimin.com/p/fd9c756f6846
來源:簡書
簡書著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請聯(lián)系作者獲得授權(quán)并注明出處。