python-selenium-spider/main_subprocess.py

27 lines
814 B
Python
Raw Normal View History

2024-03-02 03:21:47 +08:00
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.run(driver=driver)
time.sleep(5)
finally:
driver.close()
driver.quit()