There are several possibilities to get this information.
1. Hunter's Sense
A 3rd level feature of the Monster Slayer Ranger and the only ability I know of, that is explicit about those effects:
As an action, choose one creature you can see within 60 feet of you. You immediately learn whether the creature has any damage immunities, resistances, or vulnerabilities and what they are. If the creature is hidden from divination magic, you sense that it has no damage immunities, resistances, or vulnerabilities.
2. Abilitiy Checks
Intelligence (Arcana/Nature/Religion) can give you some insight concerning a creature. But it doesn't give you a guarantee.
Your Intelligence (Arcana) check measures your ability to recall lore
about spells, [...] the planes of existence, and the inhabitants
of those planes
Your Intelligence (Nature) check measures your ability to recall lore
about [...] plants and animals, the weather and natural cycles.
Your Intelligence (Religion) check measures your ability to recall
lore about deities, rites and prayers, religious hierarchies, holy
symbols, and the practices of secret cults.
But that involves only common knowledge about a creature's stats. It involves no new knowledge about a creature, it just depicts your character's potential knowledge about a particular creature. If your DM decides that your character never heard about that creature before, you cannot roll, of course.
Your magic and an offering put you in contact with a god or a god's servants. You ask a single question concerning a specific goal, event, or activity to occur within 7 days. The DM offers a truthful reply. The reply might be a short phrase, a cryptic rhyme, or an omen.
It's a bit of a stretch, but you could ask for example how you will defeat that boss to get a hint about their vulnerabilities.
4. Know Your Enemy
A 7th level feature of the Battle Master Fighter, that sort of solve your problem:
If you spend at least 1 minute observing or interacting with another
creature outside combat, you can learn certain information about its
capabilities compared to your own. The DM tells you if the creature is
your equal, superior, or inferior in regard to two of the following
characteristics of your choice:
- Strength score
- Dexterity score
- Constitution score
- Armor Class
- Current hit points
- Total class levels (if any)
- Fighter class levels (if any)