8. Given points $A$ and $B$ lie on the graphs of the linear functions $y=x$ and $y=8x$ respectively, with their x-coordinates being $a$ and $b$ ($a>0$, $b>0$). If the line $AB$ is the graph of the linear function $y=kx+m$, then when $\frac{b}{a}$ is an integer, the number of integer values of $k$ that satisfy the condition is ( ) .
(A) 1
(B) 2
(C) 3
(D) 4
8.B.

From the problem, we have $A(a, a)$ and $B(b, 8b)$. Substituting into $y=kx+m$, we get $k=\frac{8b-a}{b-a}=8+\frac{7a}{b-a}=8+\frac{7}{\frac{b}{a}-1}$.
Since $\frac{b}{a}$ and $k$ are both integers, $\frac{b}{a}=2$ or 8. Therefore, $k=15$ or 9.