Answer: Immediately shut their eyes or turn them away. If possible, move away from that place, repent humbly in the court of Allah عَزَّوَجَلَّ with remorse. If the looking person is a man then he should recite this prayer with Ṣalāt-‘Alan-Nabī before and after it:
اَللّٰهُمَّ اِنِّیْ اَعُوْذُ بِكَ مِنْ فِتْنَةِ النِّسَاءِ وَ عَذَابِ الْقَبْر
Translation: O Allah عَزَّوَجَلَّ I seek Your protection from the trouble of women and punishment of the grave.
Whenever anyone commits a sin, he should perform any good deed afterwards such as reciting Ṣalāt-‘Alan-Nabī and the Kalimaĥ Ṭayyibaĥ, etc. Sayyidunā Abū Żar Ghifārī رَضِىَ الـلّٰـهُ تَـعَـالٰی عَـنْـهُ said: The Prophet of mankind, the Peace of our heart and mind, the most Generous and Kind صَلَّى اللهُ تَعَالٰى عَلَيْهِ وَاٰلِهٖ وَسَلَّم advised me, ‘Whenever you do something evil, do any good deed after it, this good deed will erase the evil.’ I humbly asked, ‘Yā Rasūlallāĥ صَلَّى اللهُ تَعَالٰى عَلَيْهِ وَاٰلِهٖ وَسَلَّم! Is saying ‘لَآ اِلٰهَ اِلَّا اللّٰهُ’ a good deed?’ He صَلَّى اللهُ تَعَالٰى عَلَيْهِ وَاٰلِهٖ وَسَلَّم replied, ‘This is the best of good deeds.’
(Musnad Imām Aḥmad Bin Ḥanbal, vol. 8, pp. 113, Ḥadīš 21543)
Reading this blessed Ḥadīš, مَـعَـاذَ الـلّٰـه عَزَّوَجَلَّ no one must think, ‘That’s good, now I’ll do as many sins as I want and then just recite ‘لَآ اِلٰهَ اِلَّا اللّٰهُ’ and they’ll all vanish’. I swear by Allah عَزَّوَجَلَّ this is a huge and very dangerous trick of the devil. Committing a sin with the intention of repenting later on is a grave and severely major sin.