extract the band gaps via script

I have already calculated many structures—how can I extract the band gaps via script?