E
E
Eugene2020-04-28 02:40:16
Python
Eugene, 2020-04-28 02:40:16

How to change chrome profile in selenium?

I searched the internet for this issue, and this is what I found. That's just the entrance is not performed in an already existing profile, but a folder is created in the profile folder (sorry for the tautology) and everything is written there. Can I use an already existing Chrome profile?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time

options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\Eugene\AppData\Local\Google\Chrome\User Data\Profile 4")
browser = webdriver.Chrome(executable_path=r'C:\Users\Eugene\Documents\Python\chromedriver.exe', chrome_options=options)

browser.get('https://www.google.com/')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Lee, 2020-04-28
@appliks

It?

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

options = Options()
ua = UserAgent()
userAgent = ua.random
print(userAgent)
options.add_argument(f'user-agent={userAgent}')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\ChromeDriver\chromedriver_win32\chromedriver.exe')
driver.get("https://www.google.co.in")
driver.quit()

Source

L
LazyDeus, 2021-03-20
@LazyDeus

Faced the same problem recently, try this:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time

options = webdriver.ChromeOptions()
options.add_argument("--allow-profiles-outside-user-dir")
options.add_argument(r"user-data-dir=C:\Users\Eugene\AppData\Local\Google\Chrome\User Data")
options.add_argument("--profile-directory=Profile 4")

browser = webdriver.Chrome(executable_path=r'C:\Users\Eugene\Documents\Python\chromedriver.exe', chrome_options=options)

browser.get('https://www.google.com/')

https://m.habr.com/ru/sandbox/151950/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question