python 一个浏览器执行

import _thread
import subprocess
import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options


class Test:
    def __init__(self):
        self.driver = None
        self.chrome_driver = r'c:\chromedriver.exe'
        self.chrome_path = 'C:\Program Files\Google\Chrome\Application\chrome.exe'

    def open_chrome(self):
        subprocess.run([self.chrome_path, '--remote-debugging-port=9222'])

    def init_driver(self):
        _thread.start_new_thread(self.open_chrome, ())
        time.sleep(3)
        chrome_options = Options()
        chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
        self.driver = webdriver.Chrome(executable_path=self.chrome_driver, chrome_options=chrome_options)

    def run(self):
        self.init_driver()
        self.driver.get("https://www.itwenda.com/")


if __name__ == '__main__':
    Test().run()

 


关注公众号,了解更多it技术(it问答网

发表评论

电子邮件地址不会被公开。