get_user_agent_string

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

Gets 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
'Mozilla/5.0 (X11; U; Linux i686; de; rv:1.8.0.5) Gecko/20060731 Ubuntu/dapper-security...
>>> # Get a random Chrome user-agent string
>>> uas_1 = get_user_agent_string(fancy='Chrome')
>>> uas_1
'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/...

Note

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