python-selenium-spider/main_subprocess.py
2024-03-02 16:15:32 +08:00

27 lines
815 B
Python

import subprocess
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import run
import utils
# 通过 已打开的浏览器 附加 selenium
if __name__ == '__main__':
subprocess.Popen([
"C:\Program Files\Google\Chrome\Application\chrome.exe",
# "--disable-gpu",
"--remote-debugging-port=9222",
r'--user-data-dir=E:\Repository\skcks.cn\python-selenium-spider\tmp\UserData'])
# service = webdriver.ChromeService(r"./driver/chromedriver.exe")
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(options=chrome_options)
try:
run.main(driver=driver)
time.sleep(5)
finally:
driver.close()
driver.quit()