Code Monkey home page Code Monkey logo

pythonheadlesschrome's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pythonheadlesschrome's Issues

Save multiple files

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?

No funciona, no working

Buenos días,
he probado el código y no funciona ¿Como puedo arreglarlo o actualizar?
No descarga nada

download not happening

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.

using remote webdriver

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.

Need the simplest getting started

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.

Not working for Mac

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.