mirror of
https://github.com/browser-use/browser-use
synced 2026-05-06 17:52:15 +02:00
This commit modifies the `download_file.py` example to replace the `BrowserSession` and `BrowserProfile` with the new `Browser` class. The changes streamline the code and enhance clarity by directly utilizing the `Browser` for managing downloads. The download path remains set to a temporary directory for testing purposes.
35 lines
731 B
Python
35 lines
731 B
Python
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
|
|
from browser_use import Agent, Browser, ChatGoogle
|
|
|
|
api_key = os.getenv('GOOGLE_API_KEY')
|
|
if not api_key:
|
|
raise ValueError('GOOGLE_API_KEY is not set')
|
|
|
|
llm = ChatGoogle(model='gemini-2.5-flash', api_key=api_key)
|
|
|
|
|
|
browser = Browser(downloads_path='~/Downloads/tmp')
|
|
|
|
|
|
async def run_download():
|
|
agent = Agent(
|
|
task='Go to "https://file-examples.com/" and download the smallest doc file. then go back and get the next file.',
|
|
llm=llm,
|
|
browser=browser,
|
|
)
|
|
await agent.run(max_steps=25)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(run_download())
|