First of all, let's rewrite the function to integrate in a more simple way: remembering that #\sec(x)=1/\cos(x)#, and of course that #\tan(x)=\sin(x)/{\cos(x)}# we write the integrand as
#\frac{\frac{1}{\cos(x)}\frac{\sin(x)}{\cos(x)}}{\frac{1}{\cos^2(x)}-\frac{1}{\cos(x)}}#, which we can simplify into #{{\sin(x)}/{\cos^2(x)}}/{{1-\cos(x)}/{\cos^2(x)}}#, and finally obtain #\frac{-\sin(x)}{\cos(x)-1}#.
To integrate this function, we'll use a couple of substitutions: first of all, by choosing #t=\cos(x)#, one has #dt=-\sin(x)\ dx#, and so
#\int \frac{-\sin(x)}{\cos(x)-1} dx# becomes
#\int \frac{dt}{t-1}#.
By choosing #y=t-1#, one obtains #dy=dt#, and the integral becomes simply
#\int \frac{dy}{y}=\log(y)+c#. Substituting back #y=t-1#, one has #\log(t-1)+c#, and again, plugging #t=\cos(x)# into the equation, one has #\log(\cos(x)-1)+c#.
By deriving, you can check that, infact, the following equation holds:
#d/dx \log(\cos(x)-1)+c = \frac{-\sin(x)}{\cos(x)-1}#
WolframAlpha for checking the derivative