Download file with Chrome via command line

I have a file URL for a PDF that I want to download using Chrome. wget is not an option, because Chrome is seemingly sending headers and cookies that I can't replicate. So what I need is to be able to run

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --download-file http://url.etc/...

Assuming that it would send the cookies it already has for the URL domain. I have tried chrome-cli but there is no option to do something like this.

Functionally it is the same as opening a window in Chrome with the given URL, then right-clicking and hitting "Save as...". But I have a list of many PDFs that I need to download, so it has to be automated somehow.

EDIT: Meanwhile, found this.

EDIT #2: I'm not the only one! Link.


Solution 1:

Instead wget you can use cURL in conjuction with chrome. Open chrome dev tools (F12), enter network tab and start your download. Now in network tab you will see new request. Click on it with mouse right button and select "Copy as cURL (cmd)". Open command line and paste clipboard. It should look something like this:

curl "someurl" -H "Pragma: no-cache" ..... -H "Cache-Control: no-cache" --compressed

This way you will copy all headers and cookies. Add to this command -o option which will allow you to actually download file.

curl "someurl" -H "Pragma: no-cache" ..... -H "Cache-Control: no-cache" --compressed -o myfile