Ramesh-vani commited on
Commit
85e5809
·
verified ·
1 Parent(s): db399bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -51,14 +51,15 @@ def inline_resources(soup, base_url):
51
 
52
  return soup
53
 
54
- async def send_html_chunks(websocket,html):
55
-
56
  if html is not None:
 
 
 
 
 
 
57
 
58
- chunk_size = 1024
59
- for i in range(0, len(html), chunk_size):
60
- chunk = html[i:i + chunk_size]
61
- await websocket.send(json.dumps({"type": "chunk", "content": chunk}))
62
  await websocket.send(json.dumps({"type": "end", "url": url}))
63
  else:
64
  await websocket.send(json.dumps({"type": "error", "message": "Failed to fetch URL"}))
 
51
 
52
  return soup
53
 
54
+ async def send_html_chunks(websocket, html, url):
 
55
  if html is not None:
56
+ soup = BeautifulSoup(html, 'html.parser')
57
+ tags = soup.find_all(True)
58
+
59
+ for tag in tags:
60
+ tag_content = str(tag)
61
+ await websocket.send(json.dumps({"type": "chunk", "content": tag_content}))
62
 
 
 
 
 
63
  await websocket.send(json.dumps({"type": "end", "url": url}))
64
  else:
65
  await websocket.send(json.dumps({"type": "error", "message": "Failed to fetch URL"}))