We are given the integral:
\[
\int_0^\pi \frac{\tan x}{\cos x} \, dx = \int_0^\pi \frac{\sin x}{\cos^2 x} \, dx
\]
First, observe that:
\[
\tan x = \frac{\sin x}{\cos x}
\]
So, the original integral becomes:
\[
\int_0^\pi \frac{\sin x}{\cos^2 x} \, dx
\]
Now, we need to evaluate this integral. To simplify this, we perform the substitution:
\[
u = \cos x, \quad \frac{du}{dx} = -\sin x
\]
Thus, the integral becomes:
\[
\int_{u(0)}^{u(\pi)} \frac{-1}{u^2} \, du
\]
At the limits \( x = 0 \) and \( x = \pi \), we know that:
- \( \cos 0 = 1 \)
- \( \cos \pi = -1 \)
Therefore, the integral becomes:
\[
\int_1^{-1} \frac{-1}{u^2} \, du
\]
This simplifies to:
\[
- \left[ \frac{1}{u} \right]_1^{-1} = - \left( \frac{1}{-1} - \frac{1}{1} \right) = -(-1 - 1) = 2
\]
Hence, the answer is \( 2 \).