This is actually a very common occurrence in woods like pine and fir. Many would suggest that you do not use these woods for reasons just like this one. If you persist then heat is the solution. Note: this is based on untreated wood.
Not all lumber is kiln dried and even if it was you cannot guarantee the temperature it was dried at (or duration for that matter). Sap typically "sets" when heated 160°F/71°C. So if you see sap seeping out then you need to heat it up.
You need to clean it before you do any finishing (paint/stain etc). Mineral spirits is suggested as it is not likely to damage the wood.
Some woods can have the sap coming out from everywhere. If you have the means to kiln dry the wood then it would be the best course of action. It is not ideal since the effort and cost associated with saving some pine is most likely not practical. Many people have had success properly sealing it with shellac just like GLW mentions in their answer.
If you just have some small pieces like me then you could use a heat gun (Has to be a strong one) or a blowtorch. The latter can damage the wood since it is flame based but in general heat is the point.