Hướng dẫn open chrome profile python - mở hồ sơ chrome python

Hướng dẫn open chrome profile python - mở hồ sơ chrome python

Kể từ khi thông báo từ Google rằng nó sẽ vận chuyển Chrome không đầu, rất nhiều người đã chuyển sang sử dụng Python để lái Chrome. Điều này có thể được quy cho thực tế là các trình duyệt không đầu không có giao diện người dùng đồ họa (GUI), cũng như được điều hướng bằng giao diện dòng lệnh hoặc chương trình. Tuy nhiên, nhiều người chuyển sang lái xe Chrome bằng cách sử dụng Python do thực tế là nó vui hơn nhiều.

Tuy nhiên, để lái Chrome qua Python, rất nhiều người phải đối mặt với những trở ngại như mở một hồ sơ Chrome thông qua Python được yêu cầu trước khi có thể thực hiện bất kỳ hành động nào khác. Ở đây, chúng tôi sẽ thảo luận về các bước để làm theo cách mở hồ sơ Chrome thông qua Python.

Hướng dẫn từng bước để mở hồ sơ Chrome thông qua Python

  • Khởi chạy trình duyệt Chrome của bạn, sau đó nhấp vào Mở Cài đặt Chrome trong đó Chrome: // Cài đặt/được hiển thị
  • Đi đến phần người, chọn quản lý người khácManage Other people
  • Nhấp vào Thêm người
  • Nhập tên của bạn và chọn một trong nhiều biểu tượng được hiển thị
  • Bạn phải kiểm tra ‘Tạo phím tắt máy tính để bàn cho mục người dùng này
  • Nhấp vào nút Thêm.
  • Hồ sơ mới của bạn được tạo thành công
Hướng dẫn open chrome profile python - mở hồ sơ chrome python

Đây là một mẫu về cách hồ sơ mới mở của bạn sẽ trông như thế nào:

  • Bạn sẽ tìm thấy một biểu tượng máy tính để bàn được gắn thẻ Selenium - Chrome
  • Thông qua các thuộc tính của selen - chrome, hãy lấy tên của thư mục hồ sơ. ví dụ. CấmProfile-Directory = Hồ sơ 2 ″. Một ví dụ về điều này được hiển thị dưới đây:
Hướng dẫn open chrome profile python - mở hồ sơ chrome python
  • Có được đường dẫn tuyệt đối của định hướng hồ sơ trong máy tính của bạn bằng cách sử dụng các mục sau:
C:\\Users\\Otaku_Wiz\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2
  • Sau đó, truyền giá trị của định hướng hồ sơ thông qua một phiên bản của các tùy chọn bằng phương thức add_argument () cùng với dữ liệu chính của người dùng chính như được hiển thị bên dưới:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
  • Khởi động bài kiểm tra của bạn và bạn sẽ nhận thấy Chrome của bạn được bắt đầu với cấu hình Chrome là Selenium
Hướng dẫn open chrome profile python - mở hồ sơ chrome python

  • Ngày 26 tháng 11 năm 2020

Chia sẻ

Về autor

Jamiu Idowu

Doanh nhân tìm cách định hình thế giới thông qua nó và các công nghệ mới nổi. Thích nghiên cứu và viết kỹ thuật, và có thể phục vụ như một cầu nối giữa công nghệ và người dùng.

Thích bài viết này?

Chúng tôi có rất nhiều nơi mà đến từ đâu! Tham gia các thuê bao, những người đi trước gói.
Join the subscribers who stay ahead of the pack.

Bạn muốn làm cho cuộc sống của bạn dễ dàng hơn?

Sử dụng Testup, & NBSP; Công cụ tự động hóa thử nghiệm dễ nhất trên web. Don mệnh do dự và & nbsp;Testup,  the easiest test automation tool on the web. Don’t hesitate and 

Tôi muốn khởi chạy Chrome với hồ sơ mặc định của nó bằng cách sử dụng webDriver của Python để các tùy chọn cookie và trang web vẫn tồn tại trong các phiên.

Làm thế nào tôi có thể làm điều đó?

Hướng dẫn open chrome profile python - mở hồ sơ chrome python

Đã hỏi ngày 26 tháng 6 năm 2015 lúc 0:03Jun 26, 2015 at 0:03

Đây là những gì cuối cùng đã có nó làm việc cho tôi.

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)

Để tìm đường dẫn đến dữ liệu hồ sơ Chrome của bạn, bạn cần nhập chrome://version/ vào thanh địa chỉ. Cho người yêu cũ. Của tôi được hiển thị dưới dạng

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
0, để sử dụng nó trong tập lệnh tôi phải loại trừ
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
1 vì vậy chúng tôi chỉ với
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
2.

Ngoài ra, nếu bạn muốn có hồ sơ riêng biệt chỉ cho selen: thay thế đường dẫn bằng bất kỳ đường dẫn nào khác và nếu nó không tồn tại khi khởi động Chrome sẽ tạo ra hồ sơ và thư mục mới cho nó.

Đã trả lời ngày 26 tháng 6 năm 2015 lúc 0:43Jun 26, 2015 at 0:43

MadrabbitmadrabbitMadRabbit

2.2802 Huy hiệu vàng16 Huy hiệu bạc18 Huy hiệu đồng2 gold badges16 silver badges18 bronze badges

7

Điều này đã giải quyết vấn đề của tôi. (Xóa mặc định ở cuối)

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/home/username/.config/google-chrome")

cls.driver = webdriver.Chrome(options=options,
                              executable_path="./../ext/chromedriver")

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
3 IST không dùng nữa. Sử dụng
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
4 thay thế

Hướng dẫn open chrome profile python - mở hồ sơ chrome python

n1k31t4

2.6151 Huy hiệu vàng21 Huy hiệu bạc37 Huy hiệu đồng1 gold badge21 silver badges37 bronze badges

Đã trả lời ngày 25 tháng 4 năm 2018 lúc 11:53Apr 25, 2018 at 11:53

Nils Zenkernils ZenkerNils Zenker

6096 Huy hiệu bạc11 Huy hiệu đồng6 silver badges11 bronze badges

3

Tôi đã giải quyết vấn đề của mình với câu trả lời "Yoannes Geissler".

Trong trường hợp của tôi, hồ sơ của tôi được đặt tên là "Hồ sơ 2"

Mã của tôi :

options = webdriver.ChromeOptions() 

options.add_argument('--user-data-dir=C:/Users/GOD/AppData/Local/Google/Chrome/User Data')

options.add_argument('--profile-directory=Profile 2')

wd = webdriver.Chrome(options=options)

Dòng dưới đây đã giải quyết vấn đề của tôi:

options.add_argument('--profile-directory=Profile 2')

Đã trả lời ngày 14 tháng 9 năm 2020 lúc 13:31Sep 14, 2020 at 13:31

Hướng dẫn open chrome profile python - mở hồ sơ chrome python

Everest Okeverest okEverest Ok

1512 Huy hiệu bạc4 Huy hiệu đồng2 silver badges4 bronze badges

1

Chỉ để chia sẻ những gì đã làm việc cho tôi. Sử dụng hồ sơ mặc định là phức tạp, Chrome tiếp tục bị sập.

from pathlib import Path
from selenium import webdriver

driver_path = Path("{}/driver/chromedriver75.exe".format(PATH_TO_FOLDER))
user_data_dir = Path("{}/driver/User Data".format(PATH_TO_FOLDER))

options = webdriver.ChromeOptions()

# TELL WHERE IS THE DATA DIR
options.add_argument("--user-data-dir={}".format(user_data_dir))

# USE THIS IF YOU NEED TO HAVE MULTIPLE PROFILES
options.add_argument('--profile-directory=Default')

driver = webdriver.Chrome(executable_path=driver_path, options=options)

driver.get("https://google.com/")

Bằng cách thực hiện Chrome này sẽ tạo thư mục

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
5 và giữ tất cả dữ liệu trong đó tôi muốn và thật dễ dàng để chuyển dự án của bạn sang một máy khác.

Đã trả lời ngày 10 tháng 8 năm 2019 lúc 2:58Aug 10, 2019 at 2:58

1

Câu trả lời này khá đơn giản và tự giải thích.

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

exec_path_chrome = "path/to/Google Chrome" #Do not use this path that is extracted from "chrome://version/"
exec_path_driver = "path/to/chromedriver"

ch_options = Options() #Chrome Options
ch_options.add_argument("user-data-dir = /path/to/Chrome Profile") #Extract this path from "chrome://version/"

driver = webdriver.Chrome(executable_path = exec_path_driver, options = ch_options) #Chrome_Options is deprecated. So we use options instead.

driver.get("https://stackoverflow.com/a/57894065/4061346")

Như @madrabbit đã nói loại chrome://version/ vào thanh địa chỉ để tìm đường dẫn đến dữ liệu hồ sơ Chrome của bạn.

  • Nó xuất hiện như thế này trong Windows
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    options = Options()
    options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
    driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
    driver.get("https://www.google.co.in")
    0
  • Nó có vẻ như thế này trong mac
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    options = Options()
    options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
    driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
    driver.get("https://www.google.co.in")
    8

Vì vậy, tất cả những gì bạn phải làm là xóa phần cuối cùng

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
9 khỏi đường dẫn hồ sơ.

Lưu ý: Đảm bảo bạn không chạy nhiều hơn một phiên cùng một lúc để tránh các vấn đề. Make sure you don't run more than one session at the same time to avoid problems.

Đã trả lời ngày 11 tháng 9 năm 2019 lúc 17:24Sep 11, 2019 at 17:24

Hướng dẫn open chrome profile python - mở hồ sơ chrome python

Youssof H.Youssof H.Youssof H.

8593 Huy hiệu vàng14 Huy hiệu bạc35 Huy hiệu Đồng3 gold badges14 silver badges35 bronze badges

4

Đây là những gì tôi đã làm.

import chromedriver_binary
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument(r"--user-data-dir=User Data Directory")
chrome_options.add_argument(r"--profile-directory=Profile name")
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches",["enable 
logging"])
chrome_options.add_experimental_option("excludeSwitches", ["enable 
automation"])
chrome_options.add_argument("start-maximized")
self.driver = webdriver.Chrome(chrome_options=chrome_options)
self.wait = WebDriverWait(self.driver, 20)

Ở đây chúng tôi không cần phải cung cấp đường dẫn trình điều khiển Chrome.

Đã trả lời ngày 14 tháng 9 lúc 6:19Sep 14 at 6:19