![](/img/trans.png)
[英]How to initiate Chrome Canary in headless mode through Selenium and Python
[英]How to use Chrome Profiles through Headless Chrome using Selenium and Python
def __init__(self):
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=bot_data")
options.add_argument("--headless") # Runs Chrome in headless mode.
options.add_argument('--no-sandbox') # Bypass OS security model
options.add_argument('--disable-gpu') # applicable to windows os only
options.add_argument('start-maximized') #
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")
# self.driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
self.driver = webdriver.Chrome('chromedriver.exe',
options=options)
self.driver.get('https://www.google.com')
self.wait = WebDriverWait(self.driver, 10)
有我的代碼。 我想將其更改為無頭瀏覽器。 但我收到一個錯誤。
我添加了屏幕截圖以顯示錯誤。
此錯誤消息...
ERROR:devtools_http_handler.cc(288)] Error writing DevTools active port to file
...表示將DevTools 活動端口寫入所需文件時出錯。
根據如何通過 Python 打開 Chrome 配置文件中的討論,而不是通過user-data-dir
僅指定目錄名稱,您需要傳遞user-data-dir
的絕對路徑。
所以你需要替換這行代碼:
options.add_argument("user-data-dir=bot_data")
和:
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\bot_data")
您可以在以下位置找到一些相關的討論:
一些相關文件:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.