【发布时间】:2022-01-06 10:55:56
【问题描述】:
这是我的代码:
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
PATH = "driver\chromedriver.exe"
options = webdriver.ChromeOptions()
p = {"download.default_directory": "C:\\Users", "safebrowsing.enabled":"false"}
options.add_experimental_option("prefs", p)
driver = webdriver.Chrome(options=options, executable_path=PATH)
url = 'https://www.mergermarket.com/homepage'
driver.get(url)
download = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="__next"]/div/div/div[1]/div/div[2]/div[1]/div/div/div[2]/button[1]')))
download.click()
我做了一些研究,但几乎每个人都建议使用 download.default_directory 和 ChromeOptions。我确实喜欢你在上面看到的,但它没有用。好吧,代码可以工作,但我的文件是在下载中下载的,而不是我在代码中指定的路径。
【问题讨论】:
-
您需要管理员权限才能更改用户文件夹。尝试不同的目录。
-
哦,我明白了,让我们试试吧。
-
但是如果我想对用户文件夹进行更改,可以吗?
-
请不要在问题中编辑解决方案公告。接受(即单击旁边的“勾选”)现有答案之一,如果有的话。如果现有答案尚未涵盖您的解决方案,您还可以创建自己的答案,甚至接受它。比较stackoverflow.com/help/self-answer
标签: python python-3.x selenium path