This parable is taken from Scottish history. At the beginning of the fourteenth century Scottish-English relations were particularly turbulent, leading to the invasion of Scotland by King Edward I.
Robert the Bruce emerged as King of Scotland. He was crowned in 1306, and had to flee from the English immediately afterwards. Legend has it that while he was in hiding in a cave during the winter of 1306-7 he saw a spider trying to spin a web on the wall. The spider slipped many times during its attempt, but refused to give up, and eventually created a fine web. Robert the Bruce took heart from this, and was inspired to return to fight the English again, ultimately leading to victory at the Battle of Bannockburn.
This story was retold by Sir Walter Scott in his 1828 work Tales of a Grandfather. For a ripsnorting and entirely partisan rendering of Robert the Bruce's reign, try Nigel Tranter's fantastic The Bruce Trilogy.