Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from user import User
|
|
11 |
import requests
|
12 |
from watchdog.observers import Observer
|
13 |
from watchdog.events import FileSystemEventHandler
|
|
|
14 |
|
15 |
def auto_detect_mode(content):
|
16 |
if isinstance(content, str):
|
@@ -828,10 +829,30 @@ async def exe(websocket,connected,key):
|
|
828 |
response = requests.post(url, data=body, headers=headers)
|
829 |
else:
|
830 |
response = {"error": "Unsupported method"}
|
831 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
832 |
response_data = {
|
833 |
"type": "web-data",
|
834 |
-
"data":
|
835 |
}
|
836 |
await websocket.send(json.dumps(response_data))
|
837 |
elif event["command"]["type"]=="create":
|
|
|
11 |
import requests
|
12 |
from watchdog.observers import Observer
|
13 |
from watchdog.events import FileSystemEventHandler
|
14 |
+
from bs4 import BeautifulSoup
|
15 |
|
16 |
def auto_detect_mode(content):
|
17 |
if isinstance(content, str):
|
|
|
829 |
response = requests.post(url, data=body, headers=headers)
|
830 |
else:
|
831 |
response = {"error": "Unsupported method"}
|
832 |
+
# Parse HTML content
|
833 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
834 |
+
# Find and modify CSS links
|
835 |
+
for link in soup.find_all("link", rel="stylesheet", href=True):
|
836 |
+
if link['href'].startswith('/'):
|
837 |
+
css_url = url + link['href']
|
838 |
+
css_response = requests.get(css_url)
|
839 |
+
css_content = css_response.text
|
840 |
+
style_tag = soup.new_tag("style")
|
841 |
+
style_tag.string = css_content
|
842 |
+
link.replace_with(style_tag)
|
843 |
+
|
844 |
+
# Find and modify JS links
|
845 |
+
for script in soup.find_all("script", src=True):
|
846 |
+
if script['src'].startswith('/'):
|
847 |
+
js_url = url + script['src']
|
848 |
+
js_response = requests.get(js_url)
|
849 |
+
js_content = js_response.text
|
850 |
+
script_tag = soup.new_tag("script")
|
851 |
+
script_tag.string = js_content
|
852 |
+
script.replace_with(script_tag)
|
853 |
response_data = {
|
854 |
"type": "web-data",
|
855 |
+
"data": str(soup),
|
856 |
}
|
857 |
await websocket.send(json.dumps(response_data))
|
858 |
elif event["command"]["type"]=="create":
|