Python selenium 如何保持浏览器打开?

时间:2021-07-15 09:05:59

标签: python selenium selenium-webdriver

from bs4 import BeautifulSoup
import requests
from urllib.request import urlopen
import json
import time
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ElementNotVisibleException




chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
search_key = '성남 스터디카페'

url = "https://map.naver.com/v5/search/" + search_key
driverPath = "chromedriver.exe"
driver = webdriver.Chrome(driverPath, options=chrome_options)
driver.get(url)

我正在制作网络爬虫,我可以看到我输入的页面,但它在 2~3 秒后一直关闭。

我也使用了分离选项。 Chrome版本是91.0.4472.124,所以我下载了91版本的webdriver,但是浏览器还是关闭了。

我的代码有问题吗?

1 个答案:

答案 0 :(得分:0)

它正在关闭,因为主 python 进程将在运行代码后停止。 如果要保持浏览器打开,只需在末尾添加:

time.sleep(1000)
相关问题