from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
def get_chromedriver():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(r"--user-data-dir=C:\Users\ПК\AppData\Local\Google\Chrome\User Data")
chrome_options.add_argument(r"--profile-directory=Default")
s=ChromeService(executable_path=r'C:\Users\ПК\PycharmProjects\ScriptWithSelenium\chromedriver\chromedriver.exe')
driver = webdriver.Chrome(
service=s,
options=chrome_options
)
return driver
profile_dir_name = 'CustomProfile'
user_data_dir = '{0}\\AppData\\Local\\Google\\Chrome\\User Data\\{1}'.format(os.getenv('USERPROFILE'), profile_dir_name), profile_dir_name)
options.add_argument('--profile-directory={}'.format(profile_dir_name))
options.add_argument( 'user-data-dir={}'.format(user_data_dir))
None
нету none
это ваш os.getenv('USERPROFILE')
import os
def get_chromedriver():
chrome_options = webdriver.ChromeOptions()
profile_dir_name = 'Profile 66'
user_data_dir = 'C:\\Users\\ПК\\AppData\\Local\\Google\\Chrome\\User Data\\{}'.format(profile_dir_name)
print(user_data_dir)
chrome_options.add_argument('--profile-directory={}'.format(profile_dir_name))
chrome_options.add_argument('user-data-dir={}'.format(user_data_dir))
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
s=ChromeService(executable_path=r'C:\Users\ПК\PycharmProjects\ScriptWithSelenium\chromedriver\chromedriver.exe')
driver = webdriver.Chrome(
service=s,
options=chrome_options
)
return driver
def main():
driver = get_chromedriver()
driver.get('https://vk.com')
time.sleep(10)
driver.close()
driver.quit()
if __name__ =='__main__':
main()
Содержимое папки c:\Users\sergueik\AppData\Local\Google\Chrome\User Data\Profile 66
07.11.2022 18:33 <DIR> .
07.11.2022 18:33 <DIR> ..
07.11.2022 18:26 <DIR> AutofillStates
07.11.2022 18:33 <DIR> BrowserMetrics
07.11.2022 18:26 <DIR> CertificateRevocation
07.11.2022 18:33 2 338 chrome_debug.log
07.11.2022 18:26 <DIR> ClientSidePhishing
07.11.2022 18:25 <DIR> Crashpad
07.11.2022 18:26 <DIR> Crowd Deny
07.11.2022 18:25 <DIR> Default
07.11.2022 18:26 <DIR> DesktopSharingHub
07.11.2022 18:33 60 DevToolsActivePort
07.11.2022 18:26 <DIR> FileTypePolicies
07.11.2022 18:33 0 First Run
07.11.2022 18:26 <DIR> FirstPartySetsPreloaded
07.11.2022 18:26 <DIR> GrShaderCache
07.11.2022 18:26 <DIR> hyphen-data
07.11.2022 18:33 118 Last Browser
07.11.2022 18:33 13 Last Version
07.11.2022 18:33 6 741 Local State
07.11.2022 18:26 <DIR> MEIPreload
07.11.2022 18:26 <DIR> OnDeviceHeadSuggestModel
07.11.2022 18:26 <DIR> OptimizationHints
07.11.2022 18:26 <DIR> OriginTrials
07.11.2022 18:26 <DIR> PKIMetadata
07.11.2022 18:26 <DIR> pnacl
07.11.2022 18:33 <DIR> Profile 66
07.11.2022 18:26 <DIR> RecoveryImproved
07.11.2022 18:26 <DIR> Safe Browsing
07.11.2022 18:26 <DIR> SafetyTips
07.11.2022 18:26 <DIR> ShaderCache
07.11.2022 18:26 <DIR> SSLErrorAssistant
07.11.2022 18:26 <DIR> Subresource Filter
07.11.2022 18:26 <DIR> SwReporter
07.11.2022 18:26 <DIR> ThirdPartyModuleList32
07.11.2022 18:26 <DIR> UrlParamClassifications
07.11.2022 18:33 85 Variations
07.11.2022 18:26 <DIR> WidevineCdm
07.11.2022 18:26 <DIR> ZxcvbnData
7 файлов 9 355 байт
32 папок 7 389 650 944 байт свободно
c:\developer\sergueik\powershell_selenium\python>