Fetch the HTML of the current page from the browser console
(self, **kwargs)
| 81 | |
| 82 | def connect_websocket(self): |
| 83 | self.websocket = asyncio.get_event_loop().run_until_complete(websockets.connect(self.browser_console_uri)) |
| 84 | |
| 85 | async def fetch_html(self, **kwargs) -> str: |
| 86 | ''' |
| 87 | Fetch the HTML of the current page from the browser console |
| 88 | ''' |
| 89 | if not self.websocket: |
| 90 | self.websocket = websockets.connect(self.browser_console_uri) |
| 91 | print(f"Fetching HTML of current page...") |
| 92 | message = json.dumps({ |
| 93 | 'action': "fetchHTML", |
| 94 | }) |
| 95 | |
| 96 | await self.websocket.send(message) |
| 97 | response_data = json.loads(await self.websocket.recv()) |
| 98 | if not response_data.get('success'): |
| 99 | raise Exception("Failed to fetch HTML") |
| 100 | return response_data["result"] |
| 101 |
no test coverage detected