You have two possibilities in this case that doesn't require code.
Variant 1) Change the permission level of visitor When you change the permission level from "Read" to "Restricted Read" your user won't see the site contents anymore
Variant 2) Alternate read permission level of visitors You can simply remove the base permission "View Application Pages" from the "Read" Permission level.
The "site contents" is not the only place where user will see this navigation option. It is also available through the gear icon on the suite bar. By changing the permissions or permission level it will be hidden from there too.