The Spider is built from the Lego Wedo 2.0 educational kit. The movement occurs due to the operation of the crank mechanism in combination with a spur gear. As soon as you pick up the pumpkin, the distance sensor is triggered and the spider begins to get angry and swing, but immediately stops when you return the pumpkin to its place.
The set includes step-by-step building instruction and an example of program (in Lego Wedo 2.0 environment).