English 中文(简体)
如何利用 Chrome改变在塞伦ium的下载目录位置?
原标题:How to change download directory location path in Selenium using Chrome?

试图改变下载路线的Im利用Selenium 和Im。 但这要么是:

prefs = {"download.default_directory": "C:\Users\personal\Downloads\exports"}
options.add_experimental_option("prefs", prefs)`

options.add_argument("--download.default_directory --C:\Users\personal\Downloadsexports")`

没有工作。

首先,我也发现了错误。

from invalid argument: unrecognized chrome option: prefs

谁能帮助?

问题回答
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_experimental_option( excludeSwitches , [ enable-logging ])
prefs = {"profile.default_content_settings.popups": 0,    
        "download.default_directory":r"C:Usersxxxxxxxxcccxxxxxxxx", ### Set the path accordingly
        "download.prompt_for_download": False, ## change the downpath accordingly
        "download.directory_upgrade": True}
options.add_experimental_option("prefs", prefs)
driver = Chrome(service=Service(PATH), options=options)

After trying unlimited solutions on the internet, here is what works for me to set download path in Python Selenium Chrome.

from selenium.webdriver import Chrome, ChromeOptions

prefs = {
    "download.default_directory": "/Users/your_user/Desktop",
    "download.directory_upgrade": True,
    "download.prompt_for_download": False,
}

chromeOptions = ChromeOptions()
chromeOptions.add_experimental_option("prefs", prefs)
driver = Chrome(options=chromeOptions)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time

chrome_options = Options()
# chrome_options.add_argument( --headless )  # Add any additional options if needed
chrome_options.add_argument( --no-sandbox )
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument( --disable-dev-shm-usage )
#
chrome_options.add_experimental_option( prefs , {
     download.default_directory :  C:\Users\61478\PycharmProjects\WebScraper\ ,
    # download.default_directory : r C:Users61478PycharmProjectsWebScraper\ ,
     directory_upgrade : True,
     download.directory_upgrade : True,
     safebrowsing.enabled : True
})

# Pass the combined options to the Chrome WebDriver
driver = webdriver.Chrome(chrome_options)
driver.maximize_window()
driver.get( https://fastest.fish/test-files )
time.sleep(1)

# Wait for the download link to be clickable
download_link = driver.find_element(By.XPATH, "(//*[@class="table"]/tbody/tr/td/a)[1]")
download_link.click()

# Let the download complete
time.sleep(10)  # Adjust this wait time as needed

# Close the browser
driver.quit()
#
# Both path worked for me
# Spend some time tweaking this, finally find it.
#
# Chrome browser version: 120.0.6099.71  
# Selenium Version: 4.15.2




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签