如何在python中获取chrome webdriver selenium配置文件路径?

rvpgvaaj  于 2022-11-19  发布在  Python
关注(0)|答案(1)|浏览(264)

我需要“配置文件路径”从chrome://version/下载文件从这个配置文件。
我试过用

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

但它只显示了{'browserName':“铬”}。

9njqaruj

9njqaruj1#

只需导航到该页面并检索您正在查找元素。
我将插入一个完整的代码解释一步一步。

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# It is not mandatory to specify all this, but it is strongly recommended for any web scraping software
opts = Options()

# make web scraping 'invisible'
opts.add_argument("--headless")
opts.add_argument('--no-sandbox')

user_agent = "user-agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36]"
opts.add_argument(user_agent)

# ChromeDriverManager ensures no webdriver recovery issues under any supported operating system
# If you don't like this way, use the classic webdriver with the system path
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opts)

browser.get('chrome://version/')
element = browser.find_element(By.ID, "profile_path")

print(element.text)

在我例子中,输出将是:

C:\Users\giuse\AppData\Local\Temp\scoped_dir16096_1379017973\Default

相关问题