[Add] browser-use and main.py
This commit is contained in:
parent
08e64bdf45
commit
96914d44ac
221 changed files with 30952 additions and 1 deletions
43
browser-use/browser_use/dom/tests/process_dom_test.py
Normal file
43
browser-use/browser_use/dom/tests/process_dom_test.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
import anyio
|
||||
|
||||
from browser_use.browser.browser import Browser, BrowserConfig
|
||||
|
||||
|
||||
async def test_process_dom():
|
||||
browser = Browser(config=BrowserConfig(headless=False))
|
||||
|
||||
async with await browser.new_context() as context:
|
||||
page = await context.get_current_page()
|
||||
await page.goto('https://kayak.com/flights')
|
||||
# await page.goto('https://google.com/flights')
|
||||
# await page.goto('https://immobilienscout24.de')
|
||||
# await page.goto('https://seleniumbase.io/w3schools/iframes')
|
||||
|
||||
await asyncio.sleep(3)
|
||||
|
||||
async with await anyio.open_file('browser_use/dom/buildDomTree.js', 'r') as f:
|
||||
js_code = await f.read()
|
||||
|
||||
start = time.time()
|
||||
dom_tree = await page.evaluate(js_code)
|
||||
end = time.time()
|
||||
|
||||
# print(dom_tree)
|
||||
print(f'Time: {end - start:.2f}s')
|
||||
|
||||
os.makedirs('./tmp', exist_ok=True)
|
||||
async with await anyio.open_file('./tmp/dom.json', 'w') as f:
|
||||
await f.write(json.dumps(dom_tree, indent=1))
|
||||
|
||||
# both of these work for immobilienscout24.de
|
||||
# await page.click('.sc-dcJsrY.ezjNCe')
|
||||
# await page.click(
|
||||
# 'div > div:nth-of-type(2) > div > div:nth-of-type(2) > div > div:nth-of-type(2) > div > div > div > button:nth-of-type(2)'
|
||||
# )
|
||||
|
||||
input('Press Enter to continue...')
|
||||
Loading…
Add table
Add a link
Reference in a new issue