Help to understand the generalization of the Argument Principle

You can proceed similarly as in the proof of the "ordinary" argument principle. Write $$ f(z) = \frac{\prod_{j=1}^n (z-z_j)}{\prod_{k=1}^m (z-p_k)} h(z) $$ where $h$ is holomorphic and $\ne 0$ in $G$. Now take the logarithmic derivative $$ \frac{f'(z)}{f(z)} = \sum_{j=1}^n \frac{1}{z-z_j} - \sum_{k=1}^m \frac{1}{z-p_k} + \frac{h'(z)}{h(z)} $$ and multiply with $g(z)$ $$ g(z) \frac{f'(z)}{f(z)} = \sum_{j=1}^n \frac{g(z)}{z-z_j} - \sum_{k=1}^m \frac{g(z)}{z-p_k} + g(z) \frac{h'(z)}{h(z)} \\ = \sum_{j=1}^n \frac{g(z_j)}{z-z_j} - \sum_{k=1}^m \frac{g(p_k)}{z-p_k} + \left( g(z) \frac{h'(z)}{h(z)} + \sum_{j=1}^n \frac{g(z)-g(z_j)}{z-z_j} - \sum_{k=1}^m \frac{g(z)-g(p_k)}{z-p_k} \right) \, . $$ The term in parentheses has only removable singularities in $G$, therefore $$ \tag{*} g(z) \frac{f'(z)}{f(z)} = \sum_{j=1}^n \frac{g(z_j)}{z-z_j} - \sum_{k=1}^m \frac{g(p_k)}{z-p_k} + \phi(z) $$ with an holomorphic function $\phi$ in $G$.

The assertion now follows since for $a =z_1, \ldots, z_n, p_1, \ldots, p_m$ $$ \frac{1}{2 \pi i} \int_\gamma \frac{g(a)}{z-a}\, dz = g(a) \operatorname{n}(\gamma; a) $$ and $$ \frac{1}{2 \pi i} \int_\gamma \phi(z) \, dz = 0 $$ due to the Cauchy integral theorem.

Remark: Another method to obtain $(*)$ would be to observe that both $$ g(z) \frac{f'(z)}{f(z)} $$ and $$ \sum_{j=1}^n \frac{g(z_j)}{z-z_j} - \sum_{k=1}^m \frac{g(p_k)}{z-p_k} $$ are holomorphic in $A$ with the only exception of (at most) simple poles at the zeros and poles of $f$, and that the principle parts at those points are the same. Therefore the difference has only removable singularities.