You should never exhaust the bathroom fan directly into the attic.
Bathroom exaust into attic.
So can you vent a bathroom exhaust fan into the attic.
When venting a bathroom exhaust fan make sure to vent the air to the outside rather than into your attic where it can cause mold and mildew to form.
Dumping bathroom exhaust into an attic or under roof space invites costly mold contamination frost under the roof in freezing climates moisture damage to roof sheathing possibly even plywood delamination or rot roof failures and shorter roof shingle life.
Your attic is not a temperature controlled environment is never the same temperature as your living space and generally closer to the temperature outside.
It may also violate a shingle warranty.
No you cannot vent your bathroom exhaust fan into the attic.