The Science behind Electro-Magnetic Cranes

I see it all the time in movies. The protagonists are in a junkyard and just got done running from a gigantic dog or what have you. Then everything is silent. All the sudden a colossal crane swoops in from ahead and manages to suck up the adventurers by latching onto something metal. The first movie that comes to mind is Toy Story 3, but it’s a well used scene. I’ve always wondered how the big crane arms work. I know it has something to do with magnets to sort the metal out of garbage, but how does it turn on and off? After a little researched I was surprised to know I knew the answer all along. I learned it in science class many years ago. Electro-magnetic cranes function very similarly to the makeshift nail magnets we made in class when learning about electromagnetism.
In class we conducted an experiment involving a wire, a nail and a battery. To make our electromagnet we had to wrap a wire around a nail then connect the two wire tips onto opposing ends of the battery. The wires would be secured by putting a rubber band around the battery. This caused the nail to turn into an electromagnet that was strong enough to attract small metal items such as paperclips. The electricity flowing through the metal created a magnetic field around the nail. The concept is the same for electromagnetic cranes but at a grander scale. Once the electricity stops flowing, the magnetic field dissipates. That is how the crane can pick up and drop metal objects. I can’t imagine a better way of sorting metal out of massive piles of garbage. I can’t even fathom what it would be like to sort through everything without the aid of electromagnets. The little nail magnet could handle paper clips with only a battery, I wonder how much electricity electromagnetic crane require to pick up much larger metals.