@@ -50,9 +50,7 @@ Fetches real world, up-to-date user agents for use in web scraping to avoid bot
50
50
No more fake or outdated user agents, only user agents of real users.
51
51
You can either get random or usage-weighted user agents. It caches
52
52
the user agents locally to avoid unnecessary API calls, and refreshes them automatically every 24 hours
53
- from the public API of <a href =" https://useragents.me/ " >useragents.me</a >.
54
-
55
- <br ><br >
53
+ from the public API of <a href =" https://useragents.me/ " >useragents.me</a >. <br ><br >
56
54
57
55
[ ![ Donate] ( https://img.shields.io/badge/Donate-Paypal-blue?style=flat-square&logo=paypal )] ( https://www.paypal.me/smogg )
58
56
[ ![ BuyMeACoffee] ( https://img.shields.io/badge/Buy%20me%20a-Coffee-f5d132?style=flat-square&logo=buymeacoffee )] ( https://buymeacoffee.com/lennolium )
@@ -83,11 +81,11 @@ from the public API of <a href="https://useragents.me/">useragents.me</a>.
83
81
84
82
## Features
85
83
86
- - __ Up-to-date:__ No fake or outdated user agents, only real world data. Refreshed every 24 hours.
84
+ - __ Up-to-date:__ No fake or outdated user agents. ` Only real world data` , refreshed every 24 hours.
87
85
- __ Wide Support:__ User Agents for Windows, macOS, Linux, Android and iOS devices: Google Chrome, Firefox, Safari, Edge, Opera, Whale and QQ browsers.
88
86
- __ Lightweight:__ Designed to consume minimal system resources and caches user agents locally.
89
87
- __ Simple:__ Easy to use and understand with a clean and simple API.
90
- - __ Compatible:__ Supports Python 3.8 and above. Runs on Windows, macOS and Linux.
88
+ - __ Compatible:__ Supports ` Python 3.8 and above ` . Runs on Windows, macOS and Linux.
91
89
- __ Privacy:__ Protects the user by not collecting or sending any personal data.
92
90
- __ Open Source:__ Provides transparency and allows community contributions for continuous development.
93
91
@@ -118,31 +116,29 @@ Just import the package and use the convenience functions. For more advanced usa
118
116
119
117
sua.get(num = 2 , force_cached = True , mobile = True )
120
118
# [UserAgent('Mozilla/5.0 (Android ...'), UserAgent('Mozilla/5.0 (iPhone; ...')]
119
+
121
120
sua.get_list() # Returns a list of 45 or 23 (desktop/mobile) user agents as strings.
122
121
# ['Mozilla/5.0 ...', 'Mozilla/5.0 (iPhone ...', 'Mozilla/5.0 (iPhone ...', ...]
122
+
123
123
sua.get_dict() # Returns a dictionary with all desktop and mobile user agents.
124
124
# {'desktop': ['Mozilla/5.0 ...', ...] 'mobile': ['Mozilla/5.0 (iPhone ...', ...]}
125
125
```
126
126
  ;
127
127
128
128
#### Advanced Usage
129
129
130
- Import the package.
130
+ Import the package and initialize the UserAgents class to set custom settings (optional, see [ Settings and Parameters ] ( #settings-and-parameters ) for details) .
131
131
``` python
132
- from simple_useragent import UserAgents, get, get_list, get_dict, parse
133
- ```
134
-   ;
132
+ import simple_useragent as sua
135
133
136
- Initialize the class to set custom settings.
137
- ``` python
138
- user_agents = UserAgents(max_retries = 3 , timeout = 5 , cache_duration = 86400 , cache_location = ' var/cache/simple-useragent' )
134
+ simple_ua = sua.UserAgents(max_retries = 3 , timeout = 5 , cache_duration = 86400 , cache_location = ' example/path/to/folder' )
139
135
```
140
136
  ;
141
137
142
138
Fetching User Agents.
143
139
``` python
144
140
# Fetch a specified number of random mobile user agent instances.
145
- user_agents .get(num = 2 , shuffle = True , mobile = True )
141
+ simple_ua .get(num = 2 , shuffle = True , mobile = True )
146
142
# [UserAgent('Mozilla/5.0 (iPhone ...'), UserAgent('Mozilla/5.0 (iPhone; ...')]
147
143
```
148
144
  ;
@@ -151,17 +147,18 @@ You can also use the convenience functions to get user agents without initializi
151
147
``` python
152
148
get(num = 2 , force_cached = True , mobile = True )
153
149
# [UserAgent('Mozilla/5.0 (Android ...'), UserAgent('Mozilla/5.0 (iPhone; ...')]
150
+
154
151
get_list() # Returns a list of 45 or 23 (desktop/mobile) user agents as strings.
155
152
# ['Mozilla/5.0 ...', 'Mozilla/5.0 (iPhone ...', 'Mozilla/5.0 (iPhone ...', ...]
153
+
156
154
get_dict() # Returns a dictionary with all desktop and mobile user agents.
157
155
# {'desktop': ['Mozilla/5.0 ...', ...] 'mobile': ['Mozilla/5.0 (iPhone ...', ...]}
158
-
159
-
160
156
```
161
157
  ;
162
158
163
- The instance offers attributes for the user agent properties. You can also parse a custom string directly to the UserAgent class.
159
+ The instance offers attributes for the user agent properties.
164
160
``` python
161
+ # Parse a custom string directly to the UserAgent class and access its attributes.
165
162
obj = parse(' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36' )
166
163
obj.string # 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit ...'
167
164
obj.browser # 'Chrome', 'Firefox', 'Safari', 'Edge', 'IE', 'Opera', 'Whale', 'QQ Browser', 'Samsung Browser', 'Other'
@@ -173,13 +170,12 @@ The instance offers attributes for the user agent properties. You can also parse
173
170
obj[' os_version' ] # '10'
174
171
obj[' os_version_minor' ] # '0'
175
172
obj[' mobile' ] # True / False
176
-
177
173
```
178
174
  ;
179
175
180
176
#### Settings and Parameters
181
177
182
- You can set custom settings when initializing the class.
178
+ You can set custom preferences when initializing the class with ` UserAgents(max_retries=3) ` .
183
179
184
180
- __ max_retries:__ The maximum number of retries to reach the API, before falling back to local cache (default: _ 3_ ).
185
181
- __ timeout:__ The timeout in seconds for the API request (default: _ 5_ ).
@@ -188,7 +184,8 @@ You can set custom settings when initializing the class.
188
184
189
185
  ;
190
186
191
- Most functions can take the following parameters:
187
+ The functions can take the following parameters:
188
+
192
189
- __ num:__ The number of user agents to fetch (default: _ None_ = gets you all user agents available).
193
190
- __ mobile:__ Fetch mobile or desktop user agents (default: _ False_ = desktop).
194
191
- __ shuffle:__ Whether to shuffle/randomize the order of user agents (default: _ False_ = ordered by usage).
0 commit comments