-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Download Path Not Working with undetected_chrome #1935
Comments
i have the same problem |
I have a workaround. I only use the undetected chrome driver to log in. Then afterwards I copy the session to a requests.Session and do all download stuff from there. Something like the following: from selenium.webdriver import Chrome
from requests import Session
from urllib3.util import Timeout
from urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter
def get_session(browser: Chrome) -> Session:
# Enable the Network domain in the Chrome DevTools Protocol
browser.execute_cdp_cmd("Network.enable", {})
# Attempt to find the cookie from the list of all cookies, try up to three times with a 3-second wait between attempts
access_token = None
timeout_in_s = 10
timeout = time.time() + timeout_in_s
while not access_token:
# Retrieve all cookies through the CDP command
access_token = browser.execute_script("return sessionStorage.getItem('access_token');")
if isinstance(access_token, str):
access_token = access_token.strip('"')
break
if time.time() > timeout:
raise Exception(f"Access token not found in browser session after waiting {timeout_in_s} seconds.")
time.sleep(0.5)
session = Session()
session.headers.update({"Authorization": f"Bearer {access_token}"})
retries = Retry(
total=20,
backoff_factor=0.1,
status_forcelist=[400, 500]
)
session.mount('https://', HTTPAdapter(max_retries=retries))
session.mount('http://', HTTPAdapter(max_retries=retries))
return session |
How did you even get downloading to work? I keep getting this:
selenium.common.exceptions.WebDriverException: Message: You must enable downloads in order to work with downloadable files. |
I have the same problem.
|
I got it working now. Just needed to add the following:
|
This worked, thanks! Just make sure that the |
Doesn't seem to work now :( |
yeah! it worked for me, Thanks a lot
SmileyWin
***@***.***
…------------------ 原始邮件 ------------------
发件人: "Nick ***@***.***>;
发送时间: 2024年7月28日(星期天) 晚上8:08
收件人: ***@***.***>;
抄送: ***@***.***>; ***@***.***>;
主题: Re: [ultrafunkamsterdam/undetected-chromedriver] Custom Download Path Not Working with undetected_chrome (Issue #1935)
I got it working now. Just needed to add the following:
params = { "behavior": "allow", "downloadPath": storage_directory } driver.execute_cdp_cmd("Page.setDownloadBehavior", params)
This worked, thanks! Just make sure that the storage_directory is a string, not a Path.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
I was previously using the default WebDriver from Selenium for web scraping, and I had set a custom download path that was working perfectly. However, after switching to undetected_chrome, the download files are now being saved to the default downloads directory instead of the custom path I specified.
Here is my method to initialize driver:
And here is the method to set custom download path
Environment
OS: ubuntu-22.04
Python Version: 3.10
undetected_chrome Version: 3.5.5
Any help or guidance on how to resolve this issue would be greatly appreciated. Thank you!
The text was updated successfully, but these errors were encountered: