So as I described earlier, the spinning beach ball happens after I have internet (airport / wifi) enabled for a few minutes, and never happens without internet (eg, in safe mode, or with airport turned off). It happens within a minute or so of me connecting to the internet on my home router.
I took it into the apple shop and he went into Settings > Network > Location set to Automatic and the problem did not happen. However, the problem was never reproduced in the apple shop (on their wifi network, and also their ethernet network), but either way we assumed that change he made fixed the problem. Several minutes of web browsing and no problems, and it always crashes within a minute or so at home.
When I took it home I realised the problem was still happening. So it seems there is some software (??) issue with the internet connection.
However, I have been using bluetooth via tethering on my phone to connect to my iMac to the internet without any problems (except it is slow and annoying).
I decided to buy some hardware in case it fixed the problem. I bought a TP-link wifi range extender.
First I connected my tplink to the router using wifi and the configuration page on the tplink, so I could type in the router password. From now on the tplink has access to the internet through my router, and I connect to the tplink.
I tried connecting my iMac to the tplink over wifi, and it made the spinning beach balls.
Then I tried connecting my iMac to the tp link by ethernet cable (with airport turned off), and it still made the spinning beach balls.
So it turns out it is not a problem with my iMac airport, but some funny network issue that seems common to my router.
The router has not caused any problems on my android phone, iPad, or my flatmates MacAir. I checked my iMac wifi settings and they were the same as the MacAir which has had no problems (except the IP address, which is dynamically allocated, and just same.same.same.different as you'd expect).
All I can think of trying now is taking my iMac to other networks and trying to reproduce the problem (a little inconvenient as it is not a laptop), or buying a new router to replace the home router (don't really want to spend money for no reason).
Any other ideas??