selenium打开Firefox、IE、Chrome浏览器【python】
selenium打開(kāi)不同瀏覽器的腳本。
1.Firefox
from selenium import webdriver
driver=webdriver.Firefox()
driver.get("http://www.baidu.com")
'''
這里要注意打開(kāi)的域名一定要加前http://
否則會(huì)報(bào)錯(cuò):selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32603,"message":"Cannot navigate to invalid URL"}
'''
2.IE和Chrome
from selenium import webdriver
chromedriverpath="C:\Program Files (x86)\Google\Chrome\Application\chromedriver"
'''
selenium打開(kāi)IE和Chrome需要有瀏覽器驅(qū)動(dòng),需要額外下載的,chromedriverpath是驅(qū)動(dòng)路徑,在下面的的函數(shù)里面當(dāng)參數(shù)傳入。
如果想firefox直接調(diào)用會(huì)報(bào)錯(cuò):selenium.common.exceptions.WebDriverException: Message: 'chromedriver1' executable needs to be in PATH.
'''
driver=webdriver.Chrome(chromedriverpath)
driver.get("http://www.baidu.com")
?
轉(zhuǎn)載于:https://www.cnblogs.com/bbwc/p/5404662.html
總結(jié)
以上是生活随笔為你收集整理的selenium打开Firefox、IE、Chrome浏览器【python】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: winfrom 从网页中通过源代码截取
- 下一篇: python string与list互转