People get tapeworms by consuming contaminated food and water or through contact with infected stool (the fecal-oral route). You can prevent tapeworm infection by regularly washing your hands and avoiding raw or undercooked meat.