I've finally found a way to extract an installed browser's actual user-agent via Python, using only standard libraries!
It uses the http.server
library to open the teensiest little server. It serves just a few bytes of HTML and stops after the first request.
The page cannot close itself due to safety limitations built into the browser, so instead I added a redirect tag.
It's for a scraper I'm writing, which needs both the cookies and the user agent used to log in to authenticate requests. I wanted the process of getting those details to be as painless as possible for users.
#programming #Python