forked from browser-use/browser-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter_post_using_cookies.py
More file actions
42 lines (31 loc) · 1.13 KB
/
Copy pathtwitter_post_using_cookies.py
File metadata and controls
42 lines (31 loc) · 1.13 KB
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
39
40
41
42
import asyncio
import os
from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI
from pydantic import SecretStr
from browser_use import Agent
from browser_use.browser.browser import Browser, BrowserConfig
from browser_use.browser.context import BrowserContext, BrowserContextConfig
from browser_use.controller.service import Controller
load_dotenv()
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
raise ValueError('GEMINI_API_KEY is not set')
llm = ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=SecretStr(api_key))
browser = Browser(
config=BrowserConfig(
# chrome_instance_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
)
)
context = BrowserContext(browser=browser, config=BrowserContextConfig(cookies_file='twitter_cookies.txt'))
async def run_search():
agent = Agent(
browser_context=context,
task=('go to https://x.com. write a new post with the text "browser-use ftw", and submit it'),
llm=llm,
max_actions_per_step=4,
)
await agent.run(max_steps=25)
input('Press Enter to close the browser...')
if __name__ == '__main__':
asyncio.run(run_search())