The usual way to stop brake fluid leaking out when changing a brake caliper is to clamp off the brake hose close to the caliper using a 'brake hose clamp' (enter this term in a search engine to see the various styles of b.h. clamp that are available).
In the absence of a proper b.h. clamp, some people use a 'visegrips' but it's important to place packing e.g. cardboard, between the jaws of the visegrips and the hose to avoid damaging the hose - the bore of the hose is only circa 3mm so no need to clamp the hose flat or tightly, just a gentle squeeze will suffice (i.e. just reduce the hose outside diameter by about 3mm). You're going to get some air into the caliper/hose by virtue of changing the caliper, so you'll need to bleed the brakes that you worked on - probably no need to bleed all the brakes though.
Another way of preventing brake fluid loss would be to seal the brake fluid reservoir (as you yourself have suggested) - one possible easy way of doing this is to remove the reservoir cap, cover the opening with some plastic/cellophane then refit the cap.
Another way is to wedge the brake pedal partly down e.g. by using a length of wood between either the steering wheel or the seat to the brake pedal or apply a weight to hold the brake pedal partly down - you'll still have to bleed the brakes afterwards anyway. Explanation :- when the brake pedal is partly depressed it closes off the inlet port from the reservoir to the master cylinder, preventing fluid from escaping from the reservoir. There are proprietary 'brake pedal depressor' tools available (enter this term into a search engine to see what this tool looks like).
Incidentally, you probably already know this, but brake fluid is 'hygroscopic' this means it absorbs moisture (which is the main reason for changing the brake fluid at intervals set by the car manufacturer). How does moisture get into the brake fluid, you may ask?
1) Air contains moisture i.e humidity, the air space above the fluid in the reservoir is exposed to air so the moisture contained in this air can be absorbed by the brake fluid in the reservoir. Every removal of the reservoir cap allows fresh air and more moisture to enter the reservoir - there is no need to remove the cap, the reservoir on modern cars is translucent to enable the checking of fluid level without having to remove the cap. Some reservoirs have a flexible, extendable rubber diaphragm, fitted under the cap, that separates the fluid from the air space above it and follows the fluid down as the fluid level drops due to brake pad wear.
2) There may be some moisture already in the fluid that is used to top up the reservoir. When the cap is removed from the container of brake fluid, fresh air containing moisture enters the can and therefore the brake fluid. This problem gets worse as the level in the container of fluid goes down - i.e. there is more free space, so more air containing moisture enters the container and the brake fluid absorbs this new moisture -this then gets into the brake fluid reservoir when you top up the fluid. The usual advice is to not keep partly used cans of brake fluid for lengthy periods of time. Buy some new fluid, it's not expensive.
3) Believe it or not, (I've seen this mentioned in technical training literature from the brake fluid and brake system manufacturers) small amounts of moisture from the air can be absorbed through the rubber brake hoses over a lengthy period of time, this is the main reason why you encounter corrosion of components that are so far from the reservoir such as caliper pistons/bores and wheel cy;inder pistons/bores. This is another reason why the manufacturers recommend brake fluid changes at set intervals (usually every 2 years). Moisture in the brake fluid lowers the boiling point of the fluid and the water can turn to steam which is compressible, (whereas brake fluid is not compressible) resulting in the pedal going to the floor without applying the brakes. There are testers available to measure the boiling point of a sample of the brake fluid and give an indication of the %age moisture content - you shouldn't need to do this test if you change the fluid at the recommended intervals.
Final tip:- Don't shake the container of brake fluid - doing so puts tiny air bubbles into the fluid - you'll then have trouble bleeding the air out of the system and may very well have to bleed the brakes a second time a day or two later as the pedal will remain spongy. Even having the container of fluid shaking/rolling around in the boot (trunk) when bringing it home can mix air bubbles into the fluid - if this happens. leaving the container to sit for 2 -3 days should allow the entrained air to escape from the fluid and it can then be used.
Also, stick with the brake fluid recommended by the car manufacturer (typically DOT 4 spec.) - do not try to be clever by using e.g. DOT 5, Silicon based brake fluid in any system not designed to use it, otherwise, you'll really have problems (you have been warned!!).