Netscape-format cookies file generator

Converts document.cookie into a Netscape-format cookies file which is (among other things) suitable for use with wget, e.g:

wget --load-cookies cookies.txt http://example.org

Note: line breaks and other whitespace in the input don't matter.