Estimates of the Hubble constant from different cosmological probes produce discrepant results in the framework of the standard cosmological model. In order to assess whether this tension is coming from unaccounted systematic errors, or is hinting towards an extended cosmological model, independent and precise techniques to determine the Hubble constant are required. The time-delay cosmography is an emerging probe, which relies on strongly lensed variable sources. It enables to measure the Hubble constant with just a few percent precision. Current efforts are capitalised by the H0LiCOW collaboration, which uses lensed quasars as variable sources. Three analysis steps contribute to the error budget of the final estimation: measurements of the time delays of the lensed images, modeling of the gravitational potential of the lens, characterisation of the environment and the line of sight of the lensed system. H0LiCOW benefits from two different methods to estimate the contribution of the environment and the line of sight: the number counts technique and the weak lensing technique. The number counts technique is a statistical approach, which uses weighted galaxy number density in the field of the lensed systems coupled with dark matter simulations. The weak lensing technique uses the weak gravitational lensing phenomenon, encompassing the fact that the shapes of the background galaxies are unbiased tracers of matter. These two methods are complimentary and almost independent, which allows for an efficient cross-check of the systematic errors. During this thesis I developed the pipeline for the weak lensing technique, which provides quantitative characterisation of the environment and the line of sight of gravitationally lensed quasars. I worked with ground- and space-based data, and utilised state-of-art techniques, including inpainting and wavelet transform, to carry out the analysis. I applied the developed pipeline on two lensed systems, HE 0435-1223 and B1608+656. I determined that while the contribution of the structures along the line of sight is negligible for the first, it is quite significant for the second system, requiring a thorough analysis to extract the cosmological information. These results are in perfect agreement with the estimates from number counts technique. By verifying possible systematics, this gives an important support for time-delay cosmography in face of the tension in the estimates of the Hubble constant.