I've been looking into doing the same thing, and haven't found a better way other than scraping web pages or using an offline database such as the one AGPapa linked.
As far as event codes go, you can find them on the bottom of this page:
http://frclinks.frclinks.com/. Remember that for the Championship division pages the full name of the division is used rather than a code.
If you need more ideas, you could try looking through The Blue Alliance's code to see where they get their data:
https://github.com/gregmarra/the-blue-alliance