This is, quite simply, the best way to get the latest comic. It's easy to parse, and most likely to remain consistent... compared to scraping information out of the HTML page (harder, and more fragile if the page format changes), or scraping from the RSS feed (even more fragile, for the reasons davean goes into below). The JSON, however, is easy to get, easily machine-readable (there are libraries out there for pretty much any language you want to use), simple to get the data out of, and unlikely to change drastically in the future. Save yourself the pain and use it. Thank you.
The original OP has been thrown into a spoiler tag for being out-of-date (it recommends scraping the HTML, only because the JSON didn't exist yet at the point this post was made).
davean wrote:Please people, using the RSS like you are doing is just plain broken, not only does it contain other items, it only contains 3, and it might be possible none of those are comics thus requiring the script to save state and handle several edge conditions.
There are two sane ways to get the current comic, ether use http://xkcd.com/current/ which will redirect the most recent comic image or parse http://xkcd.com/ directly at which point your code will work consistently and invariantly unless the site templates change (and any time you code to an API, API changes may cause program changes).
Broken scripts are not cool. I'll sticky good scripts that are their own topic if people want.
Just please stop with the RSS junk, your code hurts me eyes. (Not only is the RSS more complicated (and none of you have even tried to do it right) but it can only be done correctly as your poll interval goes to zero)