File size: 1,076 Bytes
1f8f99f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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())