Based on the Sturm-Liouville eigenvalue problem, we develop a general analytic technique to investigate the excited states of the holographic superconductors. By including more higher order terms in the expansion of the trial function, we observe that the analytic results agree well with the numeric data, which indicates that the Sturm-Liouville method is very powerful to study the holographic superconductors even if we consider the excited states. For both the holographic s-wave and p-wave models, we find that the excited state has a lower critical temperature than the corresponding ground state and the difference of the dimensionless critical chemical potential between the consecutive states is around 5. Moreover, we analytically confirm that the holographic superconductor phase transition with the excited states belongs to the second order, which can be used to back up the numerical findings for both s-wave and p-wave superconductors.