Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,6 @@ def is_absolute(url):
|
|
19 |
return bool(urlparse(url).netloc)
|
20 |
|
21 |
def handle_protocol_relative(url, base_url):
|
22 |
-
# If the URL starts with //, prepend the protocol from the base URL
|
23 |
if url.startswith("//"):
|
24 |
parsed_base_url = urlparse(base_url)
|
25 |
return f"{parsed_base_url.scheme}:{url}"
|
@@ -30,9 +29,7 @@ def inline_resources(soup, base_url):
|
|
30 |
for link_tag in soup.find_all('link', rel='stylesheet'):
|
31 |
href = link_tag.get('href')
|
32 |
if href:
|
33 |
-
# Handle protocol-relative URLs
|
34 |
href = handle_protocol_relative(href, base_url)
|
35 |
-
# Convert relative URL to absolute URL if necessary
|
36 |
full_url = urljoin(base_url, href) if not is_absolute(href) else href
|
37 |
css_response = requests.get(full_url)
|
38 |
if css_response.status_code == 200:
|
@@ -44,9 +41,7 @@ def inline_resources(soup, base_url):
|
|
44 |
for script_tag in soup.find_all('script', src=True):
|
45 |
src = script_tag.get('src')
|
46 |
if src:
|
47 |
-
# Handle protocol-relative URLs
|
48 |
src = handle_protocol_relative(src, base_url)
|
49 |
-
# Convert relative URL to absolute URL if necessary
|
50 |
full_url = urljoin(base_url, src) if not is_absolute(src) else src
|
51 |
js_response = requests.get(full_url)
|
52 |
if js_response.status_code == 200:
|
|
|
19 |
return bool(urlparse(url).netloc)
|
20 |
|
21 |
def handle_protocol_relative(url, base_url):
|
|
|
22 |
if url.startswith("//"):
|
23 |
parsed_base_url = urlparse(base_url)
|
24 |
return f"{parsed_base_url.scheme}:{url}"
|
|
|
29 |
for link_tag in soup.find_all('link', rel='stylesheet'):
|
30 |
href = link_tag.get('href')
|
31 |
if href:
|
|
|
32 |
href = handle_protocol_relative(href, base_url)
|
|
|
33 |
full_url = urljoin(base_url, href) if not is_absolute(href) else href
|
34 |
css_response = requests.get(full_url)
|
35 |
if css_response.status_code == 200:
|
|
|
41 |
for script_tag in soup.find_all('script', src=True):
|
42 |
src = script_tag.get('src')
|
43 |
if src:
|
|
|
44 |
src = handle_protocol_relative(src, base_url)
|
|
|
45 |
full_url = urljoin(base_url, src) if not is_absolute(src) else src
|
46 |
js_response = requests.get(full_url)
|
47 |
if js_response.status_code == 200:
|