1、錯(cuò)誤腳本:
# 導(dǎo)入selenium
import time
from selenium import webdriver
# 選擇谷歌瀏覽器
driver = webdriver.Chrome(executable_path=r'C:\Program Files\python39\chromedriver.exe')
# 輸入網(wǎng)址
driver.get("https://www.baidu.com/")
# 操作網(wǎng)址
time.sleep(3)
# 打印網(wǎng)頁(yè)title
print(driver.title)
# 關(guān)閉網(wǎng)址
driver.quit()
錯(cuò)誤結(jié)果:
2、錯(cuò)誤原因
出現(xiàn) DeprecationWarning 警告的類(lèi)型錯(cuò)誤:
該類(lèi)型的警告大多屬于版本更新時(shí),所使用的方法過(guò)時(shí)的原因;某方法在當(dāng)前版本被重構(gòu),依舊可以傳入?yún)?shù),但是在之后的某個(gè)版本會(huì)被刪除。
3、解決方案
# 導(dǎo)入selenium
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# 選擇谷歌瀏覽器
s = Service(executable_path=r'C:\Program Files\python39\chromedriver.exe')
driver = webdriver.Chrome(service=s)
# 輸入網(wǎng)址
driver.get("https://www.baidu.com/")
# 操作網(wǎng)址
time.sleep(3)
# 打印網(wǎng)頁(yè)title
print(driver.title)
# 關(guān)閉網(wǎng)址
driver.quit()
?正確結(jié)果:
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-596940.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-596940.html
到了這里,關(guān)于解決python出現(xiàn)的Executable executable_path has been deprecated問(wèn)題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!