abstract-webtools 0.1.4.54__tar.gz → 0.1.4.56__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. abstract_webtools-0.1.4.56/PKG-INFO +448 -0
  2. abstract_webtools-0.1.4.56/README.md +427 -0
  3. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/setup.py +1 -1
  4. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools/abstract_webtools.py +16 -16
  5. abstract_webtools-0.1.4.56/src/abstract_webtools.egg-info/PKG-INFO +448 -0
  6. abstract_webtools-0.1.4.54/PKG-INFO +0 -206
  7. abstract_webtools-0.1.4.54/README.md +0 -185
  8. abstract_webtools-0.1.4.54/src/abstract_webtools.egg-info/PKG-INFO +0 -206
  9. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/LICENSE +0 -0
  10. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/pyproject.toml +0 -0
  11. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/setup.cfg +0 -0
  12. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools/__init__.py +0 -0
  13. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools/big_user_agent_list.py +0 -0
  14. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools/grab_source_gui.py +0 -0
  15. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools/main.py +0 -0
  16. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools/soup.py +0 -0
  17. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools/test_var.py +0 -0
  18. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools.egg-info/SOURCES.txt +0 -0
  19. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools.egg-info/dependency_links.txt +0 -0
  20. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools.egg-info/requires.txt +0 -0
  21. {abstract_webtools-0.1.4.54 → abstract_webtools-0.1.4.56}/src/abstract_webtools.egg-info/top_level.txt +0 -0
@@ -0,0 +1,448 @@
1
+ Metadata-Version: 2.1
2
+ Name: abstract_webtools
3
+ Version: 0.1.4.56
4
+ Summary: Abstract Web Tools is a Python package that provides various utility functions for web scraping tasks. It is built on top of popular libraries such as `requests`, `BeautifulSoup`, and `urllib3` to simplify the process of fetching and parsing web content.
5
+ Home-page: https://github.com/AbstractEndeavors/abstract_essentials/tree/main/abstract_webtools
6
+ Author: putkoff
7
+ Author-email: partners@abstractendeavors.com
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: abstract_webtools>=0.1.0
17
+ Requires-Dist: abstract_utilities>=0.2.0.0
18
+ Requires-Dist: PySimpleGUI>=4.60.5
19
+ Requires-Dist: urllib3>=2.0.4
20
+ Requires-Dist: requests>=2.31.0
21
+
22
+ # Abstract WebTools
23
+ Provides utilities for inspecting and parsing web content, including React components and URL utilities, with enhanced capabilities for managing HTTP requests and TLS configurations.
24
+
25
+ - **Features**:
26
+ - URL Validation: Ensures URL correctness and attempts different URL variations.
27
+ - HTTP Request Manager: Custom HTTP request handling, including tailored user agents and improved TLS security through a custom adapter.
28
+ - Source Code Acquisition: Retrieves the source code of specified websites.
29
+ - React Component Parsing: Extracts JavaScript and JSX source code from web pages.
30
+ - Comprehensive Link Extraction: Collects all internal links from a specified website.
31
+ - Web Content Analysis: Extracts and categorizes various web content components such as HTML elements, attribute values, attribute names, and class names.
32
+
33
+ ### abstract_webtools.py
34
+ **Description:**
35
+ Abstract WebTools offers a suite of utilities designed for web content inspection and parsing. One of its standout features is its ability to analyze URLs, ensuring their validity and automatically attempting different URL variations to obtain correct website access. It boasts a custom HTTP request management system that tailors user-agent strings and employs a specialized TLS adapter for heightened security. The toolkit also provides robust capabilities for extracting source code, including detecting React components on web pages. Additionally, it offers functionalities for extracting all internal website links and performing in-depth web content analysis. This makes Abstract WebTools an indispensable tool for web developers, cybersecurity professionals, and digital analysts.
36
+ ![image](https://github.com/AbstractEndeavors/abstract_essentials/assets/57512254/0451d8ea-996f-4de5-9e6c-92a606aae4ef)
37
+
38
+ - **Dependencies**:
39
+ - `requests`
40
+ - `ssl`
41
+ - `HTTPAdapter` from `requests.adapters`
42
+ - `PoolManager` from `urllib3.poolmanager`
43
+ - `ssl_` from `urllib3.util`
44
+ - `urlparse`, `urljoin` from `urllib.parse`
45
+ - `BeautifulSoup` from `bs4`
46
+
47
+
48
+ # UrlManager
49
+
50
+ The `UrlManager` is a Python class designed to handle and manipulate URLs. It provides methods for cleaning and normalizing URLs, determining the correct version of a URL, extracting URL components, and more. This class is particularly useful for web scraping, web crawling, or any application where URL management is essential.
51
+
52
+ ## Usage
53
+
54
+ To use the `UrlManager` class, first import it into your Python script:
55
+
56
+ ```python
57
+ from abstract_webtools import UrlManager
58
+ ```
59
+
60
+ ### Initializing a UrlManager Object
61
+
62
+ You can create a `UrlManager` object by providing an initial URL and an optional `requests` session. If no URL is provided, it defaults to 'www.example.com':
63
+
64
+ ```python
65
+ url_manager = UrlManager(url='https://www.example.com')
66
+ ```
67
+
68
+ ### URL Cleaning and Normalization
69
+
70
+ The `clean_url` method takes a URL and returns a list of potential URL variations, including versions with and without 'www.', 'http://', and 'https://':
71
+
72
+ ```python
73
+ cleaned_urls = url_manager.clean_url()
74
+ ```
75
+
76
+ ### Getting the Correct URL
77
+
78
+ The `get_correct_url` method tries each possible URL variation with an HTTP request to determine the correct version of the URL:
79
+
80
+ ```python
81
+ correct_url = url_manager.get_correct_url()
82
+ ```
83
+
84
+ ### Updating the URL
85
+
86
+ You can update the URL associated with the `UrlManager` object using the `update_url` method:
87
+
88
+ ```python
89
+ url_manager.update_url('https://www.example2.com')
90
+ ```
91
+
92
+ ### Extracting URL Components
93
+
94
+ The `url_to_pieces` method extracts various components of the URL, such as protocol, domain name, path, and query:
95
+
96
+ ```python
97
+ url_manager.url_to_pieces()
98
+ print(url_manager.protocol)
99
+ print(url_manager.domain_name)
100
+ print(url_manager.path)
101
+ print(url_manager.query)
102
+ ```
103
+
104
+ ### Additional Utility Methods
105
+
106
+ - `get_domain_name(url)`: Returns the domain name (netloc) of a given URL.
107
+ - `is_valid_url(url)`: Checks if a URL is valid.
108
+ - `make_valid(href, url)`: Ensures a relative or incomplete URL is valid by joining it with a base URL.
109
+ - `get_relative_href(url, href)`: Converts a relative URL to an absolute URL based on a base URL.
110
+
111
+ ## Compatibility Note
112
+
113
+ The `get_domain` method is kept for compatibility but is inconsistent. Use it only for "webpage_url_domain." Similarly, `url_basename`, `base_url`, and `urljoin` methods are available for URL manipulation.
114
+
115
+ ## Example
116
+
117
+ Here's a quick example of using the `UrlManager` class:
118
+
119
+ ```python
120
+ from abstract_webtools import UrlManager
121
+
122
+ url_manager = UrlManager(url='https://www.example.com')
123
+ cleaned_urls = url_manager.clean_url()
124
+ correct_url = url_manager.get_correct_url()
125
+ url_manager.update_url('https://www.example2.com')
126
+
127
+ print(f"Cleaned URLs: {cleaned_urls}")
128
+ print(f"Correct URL: {correct_url}")
129
+ ```
130
+
131
+ ## Dependencies
132
+
133
+ The `UrlManager` class relies on the `requests` library for making HTTP requests. Ensure you have the `requests` library installed in your Python environment.
134
+ # SafeRequest
135
+
136
+ The `SafeRequest` class is a versatile Python utility designed to handle HTTP requests with enhanced safety features. It integrates with other managers like `URLManager`, `NetworkManager`, and `UserAgentManager` to manage various aspects of the request, such as user-agent, SSL/TLS settings, proxies, headers, and more.
137
+
138
+ ## Usage
139
+
140
+ To use the `SafeRequest` class, first import it into your Python script:
141
+
142
+ ```python
143
+ from abstract_webtools import SafeRequest
144
+ ```
145
+
146
+ ### Initializing a SafeRequest Object
147
+
148
+ You can create a `SafeRequest` object with various configuration options. By default, it uses sensible default values, but you can customize it as needed:
149
+
150
+ ```python
151
+ safe_request = SafeRequest(url='https://www.example.com')
152
+ ```
153
+
154
+ ### Updating URL and URLManager
155
+
156
+ You can update the URL associated with the `SafeRequest` object using the `update_url` method, which also updates the underlying `URLManager`:
157
+
158
+ ```python
159
+ safe_request.update_url('https://www.example2.com')
160
+ ```
161
+
162
+ You can also update the `URLManager` directly:
163
+
164
+ ```python
165
+ from url_manager import URLManager
166
+
167
+ url_manager = URLManager(url='https://www.example3.com')
168
+ safe_request.update_url_manager(url_manager)
169
+ ```
170
+
171
+ ### Making HTTP Requests
172
+
173
+ The `SafeRequest` class handles making HTTP requests using the `try_request` method. It handles retries, timeouts, and rate limiting:
174
+
175
+ ```python
176
+ response = safe_request.try_request()
177
+ if response:
178
+ # Process the response here
179
+ ```
180
+
181
+ ### Accessing Response Data
182
+
183
+ You can access the response data in various formats:
184
+
185
+ - `safe_request.source_code`: HTML source code as a string.
186
+ - `safe_request.source_code_bytes`: HTML source code as bytes.
187
+ - `safe_request.source_code_json`: JSON data from the response (if the content type is JSON).
188
+ - `safe_request.react_source_code`: JavaScript and JSX source code extracted from `<script>` tags.
189
+
190
+ ### Customizing Request Configuration
191
+
192
+ The `SafeRequest` class provides several options for customizing the request, such as headers, user-agent, proxies, SSL/TLS settings, and more. These can be set during initialization or updated later.
193
+
194
+ ### Handling Rate Limiting
195
+
196
+ The class can handle rate limiting scenarios by implementing rate limiters and waiting between requests.
197
+
198
+ ### Error Handling
199
+
200
+ The `SafeRequest` class handles various request-related exceptions and provides error messages for easier debugging.
201
+
202
+ ## Dependencies
203
+
204
+ The `SafeRequest` class relies on the `requests` library for making HTTP requests. Ensure you have the `requests` library installed in your Python environment:
205
+
206
+ ```bash
207
+ pip install requests
208
+ ```
209
+
210
+ ## Example
211
+
212
+ Here's a quick example of using the `SafeRequest` class:
213
+
214
+ ```python
215
+ from abstract_webtools import SafeRequest
216
+
217
+ safe_request = SafeRequest(url='https://www.example.com')
218
+ response = safe_request.try_request()
219
+ if response:
220
+ print(f"Response status code: {response.status_code}")
221
+ print(f"HTML source code: {safe_request.source_code}")
222
+ ```
223
+
224
+ # SoupManager
225
+
226
+ The `SoupManager` class is a Python utility designed to simplify web scraping by providing easy access to the BeautifulSoup library. It allows you to parse and manipulate HTML or XML source code from a URL or provided source code.
227
+
228
+ ## Usage
229
+
230
+ To use the `SoupManager` class, first import it into your Python script:
231
+
232
+ ```python
233
+ from abstract_webtools import SoupManager
234
+ ```
235
+
236
+ ### Initializing a SoupManager Object
237
+
238
+ You can create a `SoupManager` object with various configuration options. By default, it uses sensible default values, but you can customize it as needed:
239
+
240
+ ```python
241
+ soup_manager = SoupManager(url='https://www.example.com')
242
+ ```
243
+
244
+ ### Updating URL and Request Manager
245
+
246
+ You can update the URL associated with the `SoupManager` object using the `update_url` method, which also updates the underlying `URLManager` and `SafeRequest`:
247
+
248
+ ```python
249
+ soup_manager.update_url('https://www.example2.com')
250
+ ```
251
+
252
+ You can also update the source code directly:
253
+
254
+ ```python
255
+ source_code = '<html>...</html>'
256
+ soup_manager.update_source_code(source_code)
257
+ ```
258
+
259
+ ### Accessing and Parsing HTML
260
+
261
+ The `SoupManager` class provides easy access to the BeautifulSoup object, allowing you to search, extract, and manipulate HTML elements easily. You can use methods like `find_all`, `get_class`, `has_attributes`, and more to work with the HTML content.
262
+
263
+ ```python
264
+ elements = soup_manager.find_all(tag='a')
265
+ ```
266
+
267
+ ### Extracting Links
268
+
269
+ The class also includes methods for extracting all website links from the HTML source code:
270
+
271
+ ```python
272
+ all_links = soup_manager.all_links
273
+ ```
274
+
275
+ ### Extracting Meta Tags
276
+
277
+ You can extract meta tags from the HTML source code using the `meta_tags` property:
278
+
279
+ ```python
280
+ meta_tags = soup_manager.meta_tags
281
+ ```
282
+
283
+ ### Customizing Parsing
284
+
285
+ You can customize the parsing behavior by specifying the parser type during initialization or updating it:
286
+
287
+ ```python
288
+ soup_manager.update_parse_type('lxml')
289
+ ```
290
+
291
+ ## Dependencies
292
+
293
+ The `SoupManager` class relies on the `BeautifulSoup` library for parsing HTML or XML. Ensure you have the `beautifulsoup4` library installed in your Python environment:
294
+
295
+ ```bash
296
+ pip install beautifulsoup4
297
+ ```
298
+
299
+ ## Example
300
+
301
+ Here's a quick example of using the `SoupManager` class:
302
+
303
+ ```python
304
+ from abstract_webtools import SoupManager
305
+
306
+ soup_manager = SoupManager(url='https://www.example.com')
307
+ all_links = soup_manager.all_links
308
+ print(f"All Links: {all_links}")
309
+ ```
310
+ # LinkManager
311
+
312
+ The `LinkManager` class is a Python utility designed to simplify the extraction and management of links (URLs) and associated data from HTML source code. It leverages other classes like `URLManager`, `SafeRequest`, and `SoupManager` to facilitate link extraction and manipulation.
313
+
314
+ ## Usage
315
+
316
+ To use the `LinkManager` class, first import it into your Python script:
317
+
318
+ ```python
319
+ from abstract_webtools import LinkManager
320
+ ```
321
+
322
+ ### Initializing a LinkManager Object
323
+
324
+ You can create a `LinkManager` object with various configuration options. By default, it uses sensible default values, but you can customize it as needed:
325
+
326
+ ```python
327
+ link_manager = LinkManager(url='https://www.example.com')
328
+ ```
329
+
330
+ ### Updating URL and Request Manager
331
+
332
+ You can update the URL associated with the `LinkManager` object using the `update_url` method, which also updates the underlying `URLManager`, `SafeRequest`, and `SoupManager`:
333
+
334
+ ```python
335
+ link_manager.update_url('https://www.example2.com')
336
+ ```
337
+
338
+ ### Accessing Extracted Links
339
+
340
+ The `LinkManager` class provides easy access to extracted links and associated data:
341
+
342
+ ```python
343
+ all_links = link_manager.all_desired_links
344
+ ```
345
+
346
+ ### Customizing Link Extraction
347
+
348
+ You can customize the link extraction behavior by specifying various parameters during initialization or updating them:
349
+
350
+ ```python
351
+ link_manager.update_desired(
352
+ img_attr_value_desired=['thumbnail', 'image'],
353
+ img_attr_value_undesired=['icon'],
354
+ link_attr_value_desired=['blog', 'article'],
355
+ link_attr_value_undesired=['archive'],
356
+ image_link_tags='img',
357
+ img_link_attrs='src',
358
+ link_tags='a',
359
+ link_attrs='href',
360
+ strict_order_tags=True,
361
+ associated_data_attr=['data-title', 'alt', 'title'],
362
+ get_img=['data-title', 'alt', 'title']
363
+ )
364
+ ```
365
+
366
+ ## Dependencies
367
+
368
+ The `LinkManager` class relies on other classes within the `abstract_webtools` module, such as `URLManager`, `SafeRequest`, and `SoupManager`. Ensure you have these classes and their dependencies correctly set up in your Python environment.
369
+
370
+ ## Example
371
+
372
+ Here's a quick example of using the `LinkManager` class:
373
+
374
+ ```python
375
+ from abstract_webtools import LinkManager
376
+
377
+ link_manager = LinkManager(url='https://www.example.com')
378
+ all_links = link_manager.all_desired_links
379
+ print(f"All Links: {all_links}")
380
+ ```
381
+ ##Overall Usecases
382
+ ```python
383
+ from abstract_webtools import URLManager, SafeRequest, SoupManager, LinkManager, VideoDownloader
384
+
385
+ # --- URLManager: Manages and manipulates URLs for web scraping/crawling ---
386
+ url = "example.com"
387
+ url_manager = URLManager(url=url)
388
+
389
+ # --- SafeRequest: Safely handles HTTP requests by managing user-agent, SSL/TLS, proxies, headers, etc. ---
390
+ request_manager = SafeRequest(
391
+ url_manager=url_manager,
392
+ proxies={'8.219.195.47', '8.219.197.111'},
393
+ timeout=(3.05, 70)
394
+ )
395
+
396
+ # --- SoupManager: Simplifies web scraping with easy access to BeautifulSoup ---
397
+ soup_manager = SoupManager(
398
+ url_manager=url_manager,
399
+ request_manager=request_manager
400
+ )
401
+
402
+ # --- LinkManager: Extracts and manages links and associated data from HTML source code ---
403
+ link_manager = LinkManager(
404
+ url_manager=url_manager,
405
+ soup_manager=soup_manager,
406
+ link_attr_value_desired=['/view_video.php?viewkey='],
407
+ link_attr_value_undesired=['phantomjs']
408
+ )
409
+
410
+ # Download videos from provided links (list or string)
411
+ video_manager = VideoDownloader(link=link_manager.all_desired_links).download()
412
+
413
+ # Use them individually, with default dependencies for basic inputs:
414
+ standalone_soup = SoupManager(url=url).soup
415
+ standalone_links = LinkManager(url=url).all_desired_links
416
+
417
+ # Updating methods for manager classes
418
+ url_1 = 'thedailydialectics.com'
419
+ print(f"updating URL to {url_1}")
420
+ url_manager.update_url(url=url_1)
421
+ request_manager.update_url(url=url_1)
422
+ soup_manager.update_url(url=url_1)
423
+ link_manager.update_url(url=url_1)
424
+
425
+ # Updating URL manager references
426
+ request_manager.update_url_manager(url_manager=url_manager)
427
+ soup_manager.update_url_manager(url_manager=url_manager)
428
+ link_manager.update_url_manager(url_manager=url_manager)
429
+
430
+ # Updating source code for managers
431
+ source_code_bytes = request_manager.source_code_bytes
432
+ soup_manager.update_source_code(source_code=source_code_bytes)
433
+ link_manager.update_source_code(source_code=source_code_bytes)
434
+ ```
435
+ ## License
436
+
437
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
438
+
439
+ #### Module Information
440
+ -**Author**: putkoff
441
+ -**Author Email**: partners@abstractendeavors.com
442
+ -**Github**: https://github.com/AbstractEndeavors/abstract_essentials/tree/main/abstract_webtools
443
+ -**PYPI**: https://pypi.org/project/abstract-webtools
444
+ -**Part of**: abstract_essentials
445
+ -**Date**: 10/10/2023
446
+ -**Version**: 0.1.4.54
447
+ ---
448
+