Copyright law generally allows copying for research purposes that don't compete commercially with the author's use of the work. For example, see https://w2.eff.org/IP/DMCA/Felten_v_RIAA/ (And Google, unlike some of us, can afford lawyers to press that point in court if anyone tries to sue them.)