欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python用selenium打開瀏覽器后秒關(guān)閉瀏覽器的解決辦法

 更新時(shí)間:2023年07月13日 11:16:36   作者:無糖飲料就一定無糖嗎  
最近朋友在學(xué)Selenium的時(shí)候遇到一個(gè)問題,當(dāng)執(zhí)行完selenium程序后,瀏覽器會(huì)閃退也就是自動(dòng)關(guān)閉,這篇文章主要給大家介紹了關(guān)于python用selenium打開瀏覽器后秒關(guān)閉瀏覽器的解決辦法,需要的朋友可以參考下

學(xué)習(xí)selenium的時(shí)候,上手第一個(gè)腳本發(fā)現(xiàn)成功打開瀏覽器后,代碼執(zhí)行完畢瀏覽器又秒關(guān)閉了,代碼如下:

from  selenium import webdriver
 
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")

1、檢查代碼,代碼中沒有寫driver.quit()或driver.close()方法,也沒有其它錯(cuò)誤提示;

2、檢查版本號(hào),瀏覽器版本號(hào)112.0.5615.121,驅(qū)動(dòng)版本號(hào)112.0.5615.49,確認(rèn)版本號(hào)沒有問題;

3、最后找到解決方法,如下:

from selenium import webdriver
 
options = webdriver.ChromeOptions()
options.add_experimental_option('detach', True)
 
driver = webdriver.Chrome(options=options)
driver.get('http://www.baidu.com')

python selenium默認(rèn)情況下,執(zhí)行完代碼邏輯后,瀏覽器也會(huì)自動(dòng)關(guān)閉,上述代碼可以避免瀏覽器自動(dòng)關(guān)閉。

另一種更簡便的寫法:

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
 
opt = Options()
opt.add_experimental_option('detach', True)
# 通過option參數(shù),設(shè)置瀏覽器不關(guān)閉
web = Chrome(options=opt)
web.get("https://www.lagou.com/")

總結(jié)

到此這篇關(guān)于python用selenium打開瀏覽器后秒關(guān)閉瀏覽器的解決辦法的文章就介紹到這了,更多相關(guān)selenium打開瀏覽器后秒關(guān)閉內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論