load_user_agent_strings¶
- pyhelpers.ops.load_user_agent_strings(shuffled=False, flattened=False, update=False, verbose=False)[source]¶
Load 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() >>> list(uas.keys()) ['Chrome', 'Firefox', 'Safari', 'Edge', 'Internet Explorer', 'Opera'] >>> type(uas['Chrome']) list >>> uas['Chrome'][0] 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)... >>> uas_list = load_user_agent_strings(shuffled=True, flattened=True) >>> type(uas_list) list >>> uas_list[0] # a random one 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.7...
Note
The order of the elements in
uas_list
may be different every time we run the example asshuffled=True
.