Selenium WebDriver Python 3 での Chrome プロファイルの使用
Chrome ユーザー設定を Selenium WebDriver Python 3 スクリプトに組み込もうとすると、次のような問題が発生する可能性があります。 「SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes n 16-17: truncated UXXXXXXXXscape」エラー。
この問題を解決するには、次の手順に従います。
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = webdriver.ChromeOptions() options.add_argument(r"--user-data-dir=C:\path\to\chrome\user\data") options.add_argument(r'--profile-directory=YourProfileDir') driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options) driver.get("https://www.google.co.in")
Windows で適切な Chrome プロファイル フォルダを見つけるには、目的のプロファイルに関連付けられたデスクトップ ショートカットを右クリックし、[プロパティ] > [プロパティ] に移動します。ショートカット。求めるパスが「ターゲット」テキストボックスに表示されます。
以上がSelenium WebDriver Python 3 で Chrome プロファイルを使用するときに発生する「unicodeescape」コーデック エラーを修正する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。