Chemistry - Where do the percents in empirical formula questions come from?
How would those percentages be determined in real life? Spectroscopy?
You are right, this analysis comes in the domain of analytical chemistry. The fundamental requirement for formula determination is that your sample must be extremely pure.
There is a whole field. So there are two broad classes of approaches. One is called classical analysis where one would dissolve the sample in an "appropriate" acid or base mixture, and this is followed by target element specific titration or precipitation. This technique results in very reliable data but it is very time consuming
Today most people would use an instrument called the inductively coupled plasma optical emission spectroscopy (ICP-OES), you "srpay" the dissolve sample into a state of matter (plasma) which is as hot as the surface of the Sun. Under those those conditions, compounds break down into their constituent atoms and emit characteristic wavelengths. For example, if we are interested in knowing how much aluminium is there, we would construct a calibration curve and interpolate the amount of Al in your unknown sample. The same thing (although less effectively) can be done for sulfur.
Sometimes you need both classical or instrumental analysis.