Escherichia coli is a major cause of blood stream and urinary tract infections. Owing to the spread of antimicrobial resistance, it is often treated with an inadequate antibiotic. With the aim to accelerate the diagnostics of this key pathogen, we used the flycode technology to generate nanobodies against the conserved and highly abundant outer membrane protein OmpA. Two nanobodies each recognizing a different isoform of OmpA were shown by flow cytometry to recognize > 91% of 85,680 E. coli OmpA sequences deposited in a large bacterial genome database. Crystal structures of these nanobodies in complex with the respective OmpA isoform revealed interactions with all four surface accessible loops of OmpA. Steric hindrance caused by dense O-antigen layers initially impeded reliable capture of clinical E. coli strains. By generating nanobody constructs with long linkers and by thinning the O-antigen layer through alterations to growth medium and buffers, we achieved to capture <50 CFU/mL. Our work provides a framework to generate nanobodies for the specific and sensitive detection and capture of clinically relevant pathogenic bacteria.