In many image-processing challenges, the post contains images, which must be saved to a file in order to be able to work on the problem. This is an especially tedious manual task. We programmers should not have to be subjected to such drudgery. Your task is to automatically download all the images contained in a Code Golf.SE question.
- Your program may connect to any part of
stackexchange.com, but may not connect to any other domains, excepting the locations of the images (i.e., don't bother with a URL shortener).
- An integer N is given as input, on the command line or stdin.
- The URL
http://codegolf.stackexchange.com/questions/Nis guaranteed to be a valid link to a Code Golf question.
- Each image displayed in the body of question N must be saved to a file on the local computer. Either of the following locations is acceptable:
- The current directory
- A directory input by the user
- Your program must not save files other than the images in the question body (e.g. user avatars, or images contained in answers).
- Images must be saved with the same file extension as the original.
This is a code-golf — write the shortest program you can.
Validity criterion for answers
There are various possible edge cases with multiple images of the same name, text with the same name as HTML elements, etc. An answer will be invalidated only if it can be shown to fail on some revision of a question posted before January 10, 2015.