The nozzle of the spray bottle hardens quickly which makes it impossible to use after a few days and even hours.
You can reuse the same spray over and over simply by injecting some drop of acetone, then pour it out, and do it again 3 times to be sure nothing remains. The trick is to do it just after using it (like in a few seconds). You can then use a cotton swab to limit the exposure of the plastic with the acetone (but it evaporates quite quickly so it might not be needed).
Idem for the straw and "gun" part (the black plastic part on my picture): as soon as you stop using it, put it vertical, the gun part on the top, poor quickly some acetone on the gun, it will slowly dissolve the foam (it takes 1 or 2 minutes to reach the bottom and to exit the straw ― cf. the warning below about this solution).
Bonus: **by mixing 10gr of polyurethan foam with 80gr of acetone you can waterproof stuff with this water-like substance, but only if you put several layers (at least 3). A single layer isn't hydrophilic nor waterproof, but ‘breathable’. If I remember well, each layer is pierced by some tiny bubbles and thus tiny holes. So, the more layers you add, the more waterproof (but also rigid) it becomes. With this cheap stuff I waterproof my camping gears, and humid walls. Molds can't pass through several layers. (But be careful: acetone can dissolve / destroy many stuffs like some type of plastic). If needed put a layer of paint over it at least to protect it from UV, and because, if you take the cheapest foam, it'll be UV sensitive, the coating will turn yellow, then brown after a few weeks/months (which can be quite nice).
⚠ WARNING: be very careful to not touch the mix of acetone and polyurethan foam, not even with gloves as it contains isocyanates (present in the hardener or catalyst of polyurethane-based two-part paints. It will be dissolved by acetone and will easily penetrate your skin and most gloves ― I recommend applying it using a paint roller or, if you really need to touch it, using Butyl gloves, or (cheaper) 2 layers of latex gloves under some DIY gloves made out of PP plastic bags ― latex gloves will only protect you for few minutes, maybe even seconds).
While the glue's still fresh, wet a couple of cocktails sticks or matchsticks & insert them into the nozzle & both ends of the solid part of the trigger that screws to the can's nozzle.
Cyanoacrylate is activated by water, of course, so this helps adhesion.
The flexi tube you can roll between your fingers to crack away the last use residue, or put a damp pipe-cleaner down it before it sets [you get those from craft shops these days, as no-one smokes a pipe any more;)
You then just pull all these out before next use & the residue should come with them.
A little acetone will help soften up tip of the can. Then some patience and you should be able to get it clear.
You can use some Romex cable insulation as a makeshift straw. 12/2 or 14/2 seem to work best. 14/2 being the best fit of the bunch. Just cut a piece the size you need and pull out the 3 inside wires & paper leaving just the outer shell. Place that over the can tip.
If you are asking about the consumer spray-can foams:
As the label on the can says, you should expect it to seal itself closed after the first use (or more specifically, a few hours after the first use). I don't know of a safe way to clear the can after this happens. If you insist on trying anyway, AT LEAST wear good safety goggles; getting a shot of this stuff in your face could eliminate your need to worry about using it again in the future.
You can reuse the screw-on nozzle/tube with some effort. Though since each can comes with a new one, it's unclear that the effort is worthwhile.
I really hate throwing out a still pressurized can, but that's what one has to do. They're cheap enough that this shouldn't be a serious problem, if you plan ahead and have multiple uses lined up for that day. Ideally, dispose of it as Hazardous Material, since someone else could do themselves harm by trying to puncture the can (see top of this note).
I don't know whether cartridges for the pro foam guns have the same self-sealing one-time-use property.