Add assets for the Automated Amazon Price Tracking article
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from urllib.parse import urlparse
|
||||
import re
|
||||
|
||||
|
||||
def is_valid_url(url: str) -> bool:
|
||||
try:
|
||||
# Parse the URL
|
||||
result = urlparse(url)
|
||||
|
||||
# Check if scheme and netloc are present
|
||||
if not all([result.scheme, result.netloc]):
|
||||
return False
|
||||
|
||||
# Check if scheme is http or https
|
||||
if result.scheme not in ["http", "https"]:
|
||||
return False
|
||||
|
||||
# Basic regex pattern for domain validation
|
||||
domain_pattern = (
|
||||
r"^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$"
|
||||
)
|
||||
if not re.match(domain_pattern, result.netloc):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
except Exception:
|
||||
return False
|
||||
Reference in New Issue
Block a user