Code Golf Image Downloader 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.
Rules

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/N is 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.
Mathematica, 211 210 bytes

i=Import;FileNameTake@#~Export~i@#&amp;/@ImportString["body"/.("items"/.i["http://api.stackexchange.com/2.2/questions/"&lt;&gt;InputString[]&lt;&gt;"?site=codegolf&amp;filter=!*Lgp.gEWHA6BNP.l","JSON"])[[1]],{"HTML","ImageLinks"}]


Ungolfed:

i = Import;
FileNameTake@#~Export~i@# &amp; /@ 
 ImportString[
  "body" /. (
    "items" /. 
      i["http://api.stackexchange.com/2.2/questions/" &lt;&gt; 
        InputString[] &lt;&gt; "?site=codegolf&amp;filter=!*Lgp.gEWHA6BNP.l", 
       "JSON"]
  )[[1]], 
  {"HTML", "ImageLinks"}
 ]


It's pretty straightforward. I've set up a filter for the StackExchange API, which returns only the body of a question. The code retrieves the question information with that filter and parses it as JSON. I select the correct element (the body), and use ImportString to parse the HTML and filter out all image URLs. FileNameTake@#~Export~Import@# then downloads each of the images and stores it in the current working directory with the same file name as that in the URL.

You can find out the current working directory with Directory[].

In principle, there's a much shorter version, because ImportString can actually download all the files right away, instead of just giving me the URLs. But then I lose information about the original file type (since they are converted to Image objects upon download), so I can only save them all as the same type (PNG, say).