Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -497,7 +497,37 @@ async def handle_user_input(websocket,key, process, connected,process_ids):
|
|
497 |
else:
|
498 |
response = {"error": "Unsupported method"}
|
499 |
# Parse HTML content
|
500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
# Get base URL
|
502 |
base_url = url
|
503 |
# base_host = base_url.netloc.rstrip("/")
|
|
|
497 |
else:
|
498 |
response = {"error": "Unsupported method"}
|
499 |
# Parse HTML content
|
500 |
+
souptmp = BeautifulSoup(response.text, "html.parser")
|
501 |
+
# Step 1: Define the initial HTML string
|
502 |
+
html_str = """
|
503 |
+
<!DOCTYPE html>
|
504 |
+
<html lang="en">
|
505 |
+
<head>
|
506 |
+
<meta charset="UTF-8">
|
507 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
508 |
+
<title>Sample HTML</title>
|
509 |
+
</head>
|
510 |
+
<body>
|
511 |
+
<h1>Hello, World!</h1>
|
512 |
+
</body>
|
513 |
+
</html>
|
514 |
+
"""
|
515 |
+
|
516 |
+
# Step 2: Parse the initial HTML content
|
517 |
+
soup = BeautifulSoup(html_str, 'html.parser')
|
518 |
+
|
519 |
+
# Step 3: Define the new HTML snippet to replace the body content
|
520 |
+
new_body_content = souptmp
|
521 |
+
|
522 |
+
# Step 4: Parse the new HTML snippet
|
523 |
+
new_body = BeautifulSoup(new_body_content, 'html.parser')
|
524 |
+
|
525 |
+
# Step 5: Replace the existing body content with the new content
|
526 |
+
if soup.body:
|
527 |
+
soup.body.clear()
|
528 |
+
soup.body.append(new_body)
|
529 |
+
else:
|
530 |
+
print("No <body> tag found in the HTML")
|
531 |
# Get base URL
|
532 |
base_url = url
|
533 |
# base_host = base_url.netloc.rstrip("/")
|