how can I use selenium with my normal browser

前端 未结 1 1022
长情又很酷
长情又很酷 2020-12-16 20:20

Is it possible to connect selenium to the browser I use normally instead a driver? For normal browsing I am using chrome with several plugins - add block plus, flashblock a

相关标签:
1条回答
  • 2020-12-16 21:07

    First, you need to download the ChromeDriver, then either put the path to the executeable to the PATH environment variable, or pass the path in the executable_path argument:

    from selenium import webdriver
    driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')
    

    In order to load extensions, you would need to set ChromeOptions:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = webdriver.ChromeOptions()
    options.add_extension('Adblock-Plus_v1.4.1.crx')
    
    driver = webdriver.Chrome(chrome_options=options)
    

    You can also save the chrome user profile you have and load it to the ChromeDriver:

    options = webdriver.ChromeOptions()
    options.add_argument('--user-data-dir=/path/to/my/profile')
    driver = webdriver.Chrome(chrome_options=options)
    

    See also:

    • Running Selenium WebDriver using Python with extensions (.crx files)
    • ChromeDriver capabilities/options
    0 讨论(0)
提交回复
热议问题