Generate random client hints to match user agent in python

621 views Asked by At

When sending http requests for an application I am developing, I want to use a random user agent. However, I also want to be able to send client hint request headers like 'sec-ch-ua' and 'sec-ch-ua-platform', and I want these client hints to be compatible with the user agent I have selected. Furthermore, I would like these client hints to be 'standard' in the sense that they be generated from the same distribution of client hints sent by real browsers.

I have been using https://www.useragents.me/#most-common-desktop-useragents as a bank of user agents to sample from. From this website, I get some user agent data in the form

{'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
 'os': 'Windows',
 'os_version': '10',
 'browser': 'Chrome',
 'browser_version': '114.0.0'}

I would like to use this user agent to produce data of the following form:

{'sec-ch-ua': '"Google Chrome";v="114", "Chromium";v="114", "Not=A?Brand";v="24"',
'sec-ch-ua-platform': '"Windows"'}

Since Firefox and Safari have not yet implemented client hints, I do not expect to be able to generate anything in those cases. For browsers like Chrome, I want the listed chrome/chromium versions to be higher than the browser version listed in my user agent data, and I want the 'not a brand' field to be generated in a way that would look like it was sent from an actual google chrome browser.

Does anyone know of any way to do this?

0

There are 0 answers