Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -923,58 +923,43 @@ async def exe(websocket,connected,key,process_ids):
|
|
923 |
else:
|
924 |
response = {"error": "Unsupported method"}
|
925 |
# Parse HTML content
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
link.replace_with(style_tag)
|
964 |
-
|
965 |
-
# Find and modify JS links
|
966 |
-
for script in soup.find_all("script", src=True):
|
967 |
-
if script['src'].startswith('/'):
|
968 |
-
js_url = url + script['src']
|
969 |
-
js_response = requests.get(js_url)
|
970 |
-
js_content = js_response.text
|
971 |
-
script_tag = soup.new_tag("script")
|
972 |
-
script_tag.string = js_content
|
973 |
-
script.replace_with(script_tag)
|
974 |
-
response_data = {
|
975 |
-
"type": "web-data",
|
976 |
-
"data": str(soup),
|
977 |
-
}
|
978 |
await websocket.send(json.dumps(response_data))
|
979 |
elif event["command"]["type"]=="create":
|
980 |
if event["item"]=="folder":
|
|
|
923 |
else:
|
924 |
response = {"error": "Unsupported method"}
|
925 |
# Parse HTML content
|
926 |
+
souptmp = BeautifulSoup(response.text, "html.parser")
|
927 |
+
# Step 1: Define the initial HTML string
|
928 |
+
html_str = """
|
929 |
+
<!DOCTYPE html>
|
930 |
+
<html lang="en">
|
931 |
+
<head>
|
932 |
+
<meta charset="UTF-8">
|
933 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
934 |
+
<title>Sample HTML</title>
|
935 |
+
</head>
|
936 |
+
<body>
|
937 |
+
<h1>Hello, World!</h1>
|
938 |
+
</body>
|
939 |
+
</html>
|
940 |
+
"""
|
941 |
+
|
942 |
+
# Step 2: Parse the initial HTML content
|
943 |
+
soup = BeautifulSoup(html_str, 'html.parser')
|
944 |
+
|
945 |
+
# Step 3: Define the new HTML snippet to replace the body content
|
946 |
+
new_body_content = souptmp
|
947 |
+
|
948 |
+
# Step 4: Parse the new HTML snippet
|
949 |
+
new_body = BeautifulSoup(new_body_content, 'html.parser')
|
950 |
+
|
951 |
+
# Step 5: Replace the existing body content with the new content
|
952 |
+
if soup.body:
|
953 |
+
soup.body.clear()
|
954 |
+
soup.body.append(new_body)
|
955 |
+
else:
|
956 |
+
print("No <body> tag found in the HTML")
|
957 |
+
# Inline CSS and JavaScript
|
958 |
+
soup = inline_resources(soup, url)
|
959 |
+
response_data = {
|
960 |
+
"type": "web-data",
|
961 |
+
"data": str(soup),
|
962 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
963 |
await websocket.send(json.dumps(response_data))
|
964 |
elif event["command"]["type"]=="create":
|
965 |
if event["item"]=="folder":
|