Spaces:
No application file
No application file
Download flasktest/elemFrompt.py from PrakharPratap/franklinCSS-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/PrakharPratap/franklinCSS-demo/resolve/main/flasktest/elemFrompt.py
- Command line
-
hf download hf://spaces/PrakharPratap/franklinCSS-demo/flasktest/elemFrompt.py
-
curl -L -o elemFrompt.py https://huggingface.co/spaces/PrakharPratap/franklinCSS-demo/resolve/main/flasktest/elemFrompt.py
1.08 kB
| import asyncio | |
| from pyppeteer import launch | |
| async def get_element_html(url, x, y): | |
| # const browser = await puppeteer.launch( {"headless": false, args: ['--start-maximized'] } ); | |
| browser = await launch() | |
| page = await browser.newPage() | |
| await page.setViewport({'width': 3072, 'height': 1920}) | |
| await page.goto(url) | |
| # Get the HTML element at the specified (x, y) coordinate | |
| element = await page.evaluate( | |
| '''(x, y) => { | |
| const element = document.elementFromPoint(x, y); | |
| return element ? element.outerHTML : null; | |
| }''', | |
| x, y | |
| ) | |
| await browser.close() | |
| return element | |
| async def save_html_to_file(html, filename): | |
| with open(filename, 'w') as file: | |
| file.write(html) | |
| async def main(): | |
| url = input("Enter URL: ") | |
| x = int(input("Enter X coordinate: ")) | |
| y = int(input("Enter Y coordinate: ")) | |
| filename = f'at{x}and{y}.html' | |
| html = await get_element_html(url, x, y) | |
| await save_html_to_file(html, filename) | |
| print("HTML saved to", filename) | |
| asyncio.run(main()) |