load_user_agent_strings¶
- pyhelpers.ops.load_user_agent_strings(shuffled=False, flattened=False, update=False, verbose=False)[source]¶
Loads user-agent strings for popular web browsers.
This function retrieves a partially comprehensive list of user-agent strings for Chrome, Firefox, Safari, Edge, Internet Explorer, and Opera.
- Parameters:
shuffled (bool) – Whether to randomly shuffle the user-agent strings; defaults to
False.flattened (bool) – Whether to return a flattened list of all user-agent strings; defaults to
False.update (bool) – Whether to update the backup data of user-agent strings; defaults to
False.verbose (bool | int) – Whether to print relevant information in the console; defaults to
False.
- Returns:
Dictionary or list of user-agent strings, depending on the flattened parameter.
- Return type:
dict | list
Examples:
>>> from pyhelpers.ops import load_user_agent_strings >>> uas = load_user_agent_strings() >>> type(uas) dict >>> list(uas.keys()) ['Chrome', 'Firefox', 'Safari', 'Edge', 'Internet Explorer', 'Opera'] >>> type(uas['Chrome']) list >>> uas['Chrome'][0] 'Chrome/15.0.860.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, li... >>> uas_list = load_user_agent_strings(shuffled=True, flattened=True) >>> type(uas_list) list >>> uas_list[0] # a random one 'Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Chrome...
Note
The order of the elements in
uas_listmay be different every time we run the example asshuffled=True.