This question is answered already in detail in the various visa threads (
one,
two).
But to summarise: you need a visa for Shanghai. TWOV does not apply as you will 1) be in SH for >72 hours, and 2) you are both arriving from and departing to HK, so it wouldn't qualify even if <72 hours.
You are almost always better off obtaining a Chinese visa in your home country whenever possible as you will tend to get a better visa (more entries, longer duration). There are also anecdotal reports that it has become significantly more difficult or even impossible to obtain visas in HK since 1 January, at least for some nationalities. If you really want to attempt this, get in touch with Forever Bright (+852 2369 3188 or
[email protected]) or another reputable visa agent to confirm the current situation for UK citizens.