My procedure is to make a list of all the capacitors I remove as I pull them from the PCB. Note the designator (e.g., C2), the rating (330u, 200V), the pin spacing (10mm), the diameter (22mm), and the height. The height is usually the parameter that can vary the most, assuming there's no constraint due to overhead heatsinks or whatever.
For the film capacitors (I replace all primary-side film caps as well), note the designator, capacity, voltage rating (you might see both AC and/or DC ratings -- source your replacement based on AC rating of 250V or higher), pin spacing, LxWxH, and safety rating. There should be a mark that says X2 or X1Y1 or something like that. Try to match it like-for-like, or read up on what the rating means and make sure you understand where you can substitute.
For ceramic disc capacitors, it's much the same as the film caps. Capacity (usually expressed as a three-digit code, like 472 -- look it up or use an online calculator to convert), AC voltage rating, pin spacing, approximate size (if there's anything nearby), and safety rating.
On Digikey, I filter first by brand (I stick to Nichicon), through-hole, in stock, the exact capacity and pin spacing, then hit search and refine what's left to remove packaging that I can't buy (e.g., tape-and-reel -- high quantity stuff like that), then diameter (equal or thinner), height (if it matters), search again. Then, I select 105C parts only, and refine that to only those that specify lifetimes of at LEAST 3000 hours @ 105C. If I can't find anything in a suitable (or higher) voltage rating at that temperature and lifetime spec, I will bend to 2000 hours @ 105C, but that's pretty rare.
Film and ceramic caps are usually so plentiful that I substitute exactly the same specs just to limit to the dozen or so contenders, then I pick the pretty blue one as a tie-breaker.