AppleScript to click buttons and close tabs
Assuming these links are going to be in the same place every time, I'd try Watch Me Do (open up Automator, tell it you want an application. There are lots of built-in actions in the "Internet" subsection of Library, Website Popup looks promising for you. 

If that all fails or you want something quick and dirty, pressing the Record button up at the top right will record your screen and keyboard inputs, as well as events for you. You could just code a loop to run the generated code over and over again N times, but be warned that Watch Me Do (the thing activated by record) is only screen scraping. If those links ever move or your window isn't in the same place, the script will bomb, probably clicking on things you don't want it to at all, so be careful!