You could have a look a the engine source code and see how the builtin editor handles export. Since it's all open source, what you'd like to do is certainly possible, but I don't think there are any prebuilt solutions, and I don't think HTML5 export is currently scriptable via GDScript. I may be wrong, though.
What you could try is to use the command line export option. Once you know how to export from the command line, you can script that with GDScript using OS.execute.