繁体   English   中英

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

[英]How to get chrome webdriver selenium path to profile files in python?

我需要来自 chrome://version/ 的“配置文件路径”才能从此配置文件下载文件。

我尝试使用

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

但它只显示 {'browserName': 'chrome'}。

只需导航到该页面并检索您要查找的元素。

我将插入一个完整的代码来逐步解释。

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)

output,就我而言,将是:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM