4. Given the equation of line $A B$ is: $y=k x+m$ passing through points $A(a, a), B(b, 8 b)(a>0, b>0)$. When $\frac{b}{a}$ is an integer, the number of integer $k$ that satisfies the condition is ( ).
(A) 1
(B) 2
(C) 3
(D) 4
4. B.

When $a=b$, since $a=b=0$ does not meet the problem's conditions, we have $a \neq b$.
Thus, $k=\frac{a-8 b}{a-b}=\frac{1-8 \times \frac{b}{a}}{1-\frac{b}{a}}$.
Let $\frac{b}{a}=t$. Then,
$$
k=\frac{1-8 t}{1-t}=8-\frac{7}{1-t}=8+\frac{7}{t-1} .
$$

Since $\frac{b}{a}=t$ is a positive integer not equal to 1, and $k$ is an integer, we have,
$$
t-1=1,7 \Rightarrow t=2,8 \Rightarrow k=9,15 .
$$