get_user_agent_string

pyhelpers.ops.get_user_agent_string(fancy=None, **kwargs)[source]

Get a random user-agent string for a specified browser.

Parameters:
  • fancy (None | str) – Name of the preferred browser; options include 'Chrome', 'Firefox', 'Safari', 'Edge', 'Internet Explorer' and 'Opera'. If fancy=None (default), the function returns a user-agent string from a randomly-selected browser among all available options.

  • kwargs – [Optional] Additional parameters for the function get_user_agent_strings().

Returns:

A user-agent string for the specified browser.

Return type:

str

Examples:

>>> from pyhelpers.ops import get_user_agent_string
>>> # Get a random user-agent string
>>> uas_0 = get_user_agent_string()
>>> uas_0
'Opera/7.01 (Windows 98; U)  [en]'
>>> # Get a random Chrome user-agent string
>>> uas_1 = get_user_agent_string(fancy='Chrome')
>>> uas_1
'Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrom...

Note

In the above examples, the returned user-agent string is random and may be different every time of running the function.