shawnbutton / pythonheadlesschrome Goto Github PK
View Code? Open in Web Editor NEWTemp repo for headless chrome download
Temp repo for headless chrome download
Would it be possible for you to confirm that this still works for Chrome version 75.0.3770.80 under Windows?
I can't get it to work and I am concerned that, as per the final threads in https://bugs.chromium.org/p/chromium/issues/detail?id=696481, that your solution no longer works.
Thanks so much.
I need to download multiple files. This solution works perfectly. The issue I have is that each downloaded file has the same file name so the first one writes over the second one etc... If i dont do it in headless it just appends a number at the end which i can rename.
So for example I have 2 files:
download.pdf
download.pdf
in non headless it would download these as download.pdf, download.pdf (1) etc...
but in headless the second file writes over the first one.
any ideas ho i could get around this?
Buenos días,
he probado el código y no funciona ¿Como puedo arreglarlo o actualizar?
No descarga nada
Hi Shawn,
First thanks so much for writing this. I need headless download pretty bad so was excited to see you had something going. I have a JS heavy front end i need to be able to download in headless mode. Quite simply I can get your code running just fine, but it doesn't download. If I flip the headless flag my downloads happen. My assert fails after wait_for_file_to_exist times out. I wish I could share the page but it is private. Any idea on how to start debugging this would be helpful. I'm using:
Chrome Version 63.0.3239.108 (Official Build) (64-bit)
ChromeDriver 2.34.522932
python selenium (3.8.0)
the failing code is the assert after:
wait_until_file_exists(actual_file, 10)
assert (os.path.isfile(actual_file))
i am getting this response after enable_download_in_headless_chrome():
response from browser:
result:sessionId:1c43c8fa88866870389be5896efe77ed
result:status:0
result:value:None
Update After more investigation it appears that I can successfully run your code with my config so it must be something with the page I'm trying to interact with in headless mode. I'm investigating further and post my findings here in case someone else runs into the issue.
Update 2 I've found that the page should open a new chrome tab when clicking download, download the file and then close the tab. After clicking download the new tab doesn't open in headless mode. So I'm investigating tabs now.
I'm trying to use a remote webdriver instead of the chrome webdriver...I made this change in driver_builder.py:
# driver = Chrome(executable_path=driver_path, chrome_options=chrome_options)
driver = Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=chrome_options.to_capabilities())
Once execution gets to the 'command_result = driver.execute("send_command", params)' in the 'enable_download_in_headless_chrome' method I am running into an issue.
Here is some information:
selenium.common.exceptions.WebDriverException: Message: POST /session/a2908a00-707a-4be3-97a1-c79aec8e0e1e/chromium/send_command
Build info: version: '2.49.1', revision: '7203e46', time: '2016-01-21 17:35:35'
System info: host: 'abc-Mac-mini', ip: '000.000.00.000', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '9'
Driver info: driver.version: unknown
I would appreciate any information you have on how to solve the driver.version: unknown problem. This "Issue" may not be directly related to your code, but I thought it was worth asking as you may have some insight.
Thanks.
Personally, I am a bit of Python noob. Can work my way around well, can see what you are doing... but could you add a readme.md with a simple how to? Thanks.
I copied over as you have but I am having issues on my end. Downloading files with headed Chrome is fine, but can't get it with Chrome headless. I'm running Chrome 66 on MacOSX, Python 3, Selenium 3.11
#Initial settings
chrome_path = root_dir + "software/chromedriver"
chrome_profile = chrome_webdriver.Options()
profile = {
'download.default_directory' : data_dir,
"download.prompt_for_download": False,
"download.directory_upgrade": True,
'safebrowsing.enabled': False,
'safebrowsing.disable_download_protection': True
}
chrome_profile.add_experimental_option('prefs', profile)
chrome_profile.add_argument("--headless")
And then...
#Once browser is launched, execute following command to "enable" headless downloading
browser.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': data_dir}}
command_result = browser.execute("send_command", params)
print("response from browser:")
for key in command_result:
print("result:" + key + ":" + str(command_result[key]))
Program runs without errors, but cannot download as I was able to in headed mode. Anything different from Mac to Windows?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.