Your questions cover a huge part of what astrophysics is in fact. Since it is an entire field of study I'm not going to answer with deep explanations since that would take an entire month to write a small introduction to the topic.
But what if the spectrum is super packed by different wave lengths?
If many spectral lines are packed together it becomes increasingly important to do high resolution spectroscopy (which can clearly discern between very similar frequencies of light). Usually stellar atmospheres have more single atoms than complex molecules in it so stellar spectral lines are usually very simple and easy to identify. There are parts of the spectrum that are complicated to understand in different situations, for example the Diffuse Interstellar Bands (DIBs) which are many spectral lines so tightly packed together that we haven't been able to identify them for now, these are probably produced by complex molecules in the interstellar gas. Spectral lines that are simple to understand can also become complicated if there are other important effects at play; for example the Zeeman effect and the Stark effect can make single spectral lines to split in two components depending on the intensity of the magnetic or the electric present around the atoms emmiting the light, and Doppler shifts due to surface motion of material in the star can add a lot of noise to these lines until even with high-resolution spectroscopy lines look more like fuzzy wide sectors. So, yeah it is a hard problem to solve in many cases but it can be done for enought lines to actually get the global chemistry and the proportion of light elements against heavy ones (metallicity) inside the star.
How do we calculate the weight of the object?
Weight is a force which depends on the mass of the object and the local gravitational acceleration. A more precise question is how do we know stellar masses? The answer is binary systems. Using Kepler's laws and the period of binaries we can discover what gravitational influence each component of the system has on the other and thus we can derive the mass of each star. For single stars it is more complicated, we can use stellar models created by studying the characteristics of known stellar masses in binary systems and show that there are correlations between chemical composition, temperature and luminosity that allow to determine the mass of a star using those variables; this can be done by determining the correct spectral type and luminosity class of the star (using spectrography or photometry) to get the actual parameters of the object. There are other stars that exhibit relations between their mass and their periodic pulsations, those variable stars can become also good standards for more detailed stellar models that can be applied to the study of other stars with unknown mass. Also there is Asterosysmology, which studies how stars react to mechanical perturbations, they ring like bells making different parts of it oscillate in very specific manners depending on the mass and size of the star.
How do we calculate the distance and speed of the object?
Well this is the entire field of astrometry in fact. We use trigonometry and the movement of Earth around the Sun to detect the parallax of stars and infer distances to them. For distant stars this becomes less and less accurate and you need to use other methods (that have been calibrated using the known distances to nearby stars) like Cepheid variables and other standard candles in what is known as the cosmic distance ladder. The European Space Agency Gaia mission is currently performing parallax measurements for nearly 2 billion stars (1% of the stellar population of our galaxy). For stellar motion we can measure the proper motion of stars (the apparent tangential motion in the sky) by accurately measuring their positions in the sky throughout many years (something that the Gaia mission is also doing). But to be able to understand the actual tangential motion of the star you need to add distance measurements to these proper motion ones. Finally you need the third component of the motion vector of the star en 3D space, the radial motion (towards or away from Earth), that can be done to an accuracy of even meters per second speeds by radial velocity measurements (which are done by measuring the Doppler shifts of the spectral lines).
How are we sure that light traveling towards Earth is not emitted by some other object behind the subject?
Stars are opaque so no light can come from behind it. What could happen is that you are seen the chemical signature of interstellar gas in front of the star in the spectrum. That could be material that casualy got in the line of sight between us and the star. Indeed the chemical composition of interfering gas could appear in the spectral analysis. For the spectral lines due to the molecules present in our atmosphere we have such a good knowdledge of where those lines are located and what intensity they have that we can subtract any stellar spectrum by the telluric spectrum (Earth's atmospheric spectrum) easily. To discern spectral lines coming from absorption by interstellar gas we can do radial velocity measurements for each line and discover that some of the lines move in some way and others in another way, that means spectral lines from the star detach from spectral lines from interfering matter since in general you should expect the motion of the star be completely random and independent from the motion of the interstellar gas in the line of sight. After making many of those measurements you can also start to create a chemical model of the interstellar gas and finally subtract it like in the case of the telluric lines. Also theoretical models show that complex molecules can't survive close to the star and thus lines produced by thos molecules shouldn't be confused with stellar spectral features.