URLExtract is a Python library for collecting and extracting URLs from a given text based on locating Top-Level Domains (TLDs). It is currently at version 1.9.0 and is actively maintained, with regular updates to its TLD list and ongoing Python version compatibility.
pip install urlextractVerified import paths — ran on the pinned version, not inferred.
Initializes the URLExtract class and uses the `find_urls` method to extract all URLs from a given text string.
Review extracted URLs in contexts where non-URL patterns might coincidentally contain TLDs. Consider using the `with_schema_only=True` parameter in `find_urls` if you only need URLs with explicit schemes (e.g., 'http://', 'https://').
Ensure the application has write permissions to the default cache directory or a custom directory specified during `URLExtract` initialization. Manually update the TLD list using `extractor.update()` if necessary. Consider reporting the issue on the GitHub repository for specific edge cases.
Upgrade to Python 3.7 or newer. Python 3.12 support was added in v1.9.0.
Upgrade to version 1.9.0 or later to benefit from fixes for Markdown link parsing and mixed-case hostname filtering.
Install the library using pip, then ensure it's imported correctly. ```python pip install urlextract # In your Python code from urlextract import URLExtract ```
Replace all occurrences of `extract_urls` with `find_urls`.
```python
extractor = URLExtract()
urls = extractor.find_urls("text with a url.com and another.net")
```Convert the input data to a string before passing it to the `urlextract` method.
```python
extractor = URLExtract()
# Correcting integer input
urls = extractor.find_urls(str(1234567890))
# Correcting list input (example)
text_parts = ["visit example.com", "or check out test.org"]
urls_from_list = extractor.find_urls(" ".join(text_parts))
```Verify your internet connection, check firewall settings, or try running the `update()` method again later when network conditions are stable.
```python
import requests
from urlextract import URLExtract
extractor = URLExtract()
try:
extractor.update()
print("TLD list updated successfully.")
except requests.exceptions.ConnectionError as e:
print(f"Failed to update TLDs due to connection error: {e}")
print("Please check your internet connection and firewall settings.")
except Exception as e:
print(f"An unexpected error occurred during TLD update: {e}")
```