
BrowserPilot快速上手教程3步配置Chromedriver與OpenAI5分鐘跑通自然語言瀏覽器自動化【免費(fèi)下載鏈接】browserpilotNatural language browser automation項(xiàng)目地址: https://gitcode.com/gh_mirrors/br/browserpilotBrowserPilot是一個用自然語言控制瀏覽器的開源工具你只需用英語寫下打開谷歌、點(diǎn)擊搜索框、輸入關(guān)鍵詞這樣的指令它就會自動打開 Chrome 瀏覽器替你完成網(wǎng)頁操作、信息提取甚至自動登錄非常適合做網(wǎng)頁自動化、數(shù)據(jù)抓取和爬蟲測試。整個上手流程只有 3 個配置步驟5 分鐘即可跑通第一個自然語言瀏覽器自動化任務(wù)。一、為什么選擇 BrowserPilot傳統(tǒng)瀏覽器自動化如手寫 Selenium 腳本最大的痛點(diǎn)是網(wǎng)頁稍有改版腳本就報廢。BrowserPilot 的思路完全不同——它把 GPT 接在了 Selenium 上 你寫的不是代碼而是一行行自然語言指令 GPT 負(fù)責(zé)把指令實(shí)時翻譯成 Selenium 代碼并執(zhí)行 內(nèi)置記憶模塊能記住瀏覽過的頁面內(nèi)容并做總結(jié)一句話像寫文檔一樣寫自動化腳本。二、快速開始3步完成配置第 1 步安裝 BrowserPilot打開終端執(zhí)行pip install browserpilot要求 Python 3.10 以上依賴項(xiàng)見 pyproject.toml。第 2 步配置 Chromedriver從 Chromium 官網(wǎng)下載最新的Chromedriver穩(wěn)定版解壓后放到你的指令文件同目錄例如項(xiàng)目根目錄下的./chromedriver如果權(quán)限受限Mac 上常見右鍵解壓出的 chromedriver → 選擇打開解除限制確保 Python 能調(diào)用它第 3 步設(shè)置 OpenAI API Key用你習(xí)慣的方式創(chuàng)建環(huán)境變量export OPENAI_API_KEY你的API密鑰到這里配置就全部完成了。?三、5分鐘跑通第一個自然語言瀏覽器自動化任務(wù)1. 寫指令文件創(chuàng)建instructions.yaml可參考 prompts/examples/buffalo_wikipedia.yaml 這個現(xiàn)成例子instructions: - Go to Google.com - Find all textareas. - Find the first visible textarea. - Click on the first visible textarea. - Type in buffalo and press enter. - Wait 2 seconds. - Find all anchor elements that link to Wikipedia. - Click on the first one. - Wait for 10 seconds.2. 運(yùn)行任務(wù)項(xiàng)目自帶命令行入口 examples.py一條命令即可執(zhí)行python examples.py selenium instructions.yaml --chromedriver_path ./chromedriver瀏覽器會自動彈出Google 搜索框被點(diǎn)擊、buffalo 被輸入、維基百科鏈接被打開——全程零代碼。3. 也可以像調(diào)用庫一樣使用from browserpilot.agents.gpt_selenium_agent import GPTSeleniumAgent with open(instructions.yaml) as f: agent GPTSeleniumAgent(f, ./chromedriver) agent.run()核心實(shí)現(xiàn)都在 browserpilot/agents/gpt_selenium_agent.py。四、寫好自然語言指令的技巧指令寫得好不好直接決定自動化成功率。經(jīng)驗(yàn)法則像給 Copilot 寫代碼提示詞而不是聊天? 口語化寫法? 推薦寫法find the search boxfind all textareasthe login buttonbutton which says Log infind all the visible textareasfind all the textareas → 再寫一行 find the first visible textarea小技巧 用 HTML 元素術(shù)語textarea、anchor、input而不是 text box?? 把復(fù)雜動作拆成多行每行只做一件事? 用BEGIN_FUNCTION func_name/END_FUNCTION包裹指令塊再用RUN_FUNCTION func_name調(diào)用即可復(fù)用 編譯后的指令可存成 yamlinstruction_output_file參數(shù)避免重復(fù)調(diào)用 API 花錢更多可抄作業(yè)的示例prompts/examples/nytimes_click_login.yaml、prompts/examples/instagram.yaml、prompts/examples/memory_summarization.yaml。五、項(xiàng)目結(jié)構(gòu)速覽智能體核心browserpilot/agents/gpt_selenium_agent.py —— 定義了點(diǎn)擊、輸入、滾動、截圖、記憶查詢等全部動作指令編譯器browserpilot/agents/compilers/instruction_compiler.py —— 負(fù)責(zé)把自然語言編譯成可執(zhí)行動作記憶模塊browserpilot/agents/memories/ —— 讓智能體總結(jié)并回憶瀏覽過的頁面示例指令庫prompts/examples/六、安全提醒?? BrowserPilot 會執(zhí)行 GPT 生成的 Python 代碼官方在 README 中明確提示這并非安全慣例。請只讓它在本地、可信的瀏覽器環(huán)境中運(yùn)行對重要賬號操作保持警惕指令越精確越安全總結(jié)BrowserPilot 讓瀏覽器自動化從寫脆弱的代碼變成寫英文說明書。只需pip 安裝 → 放好 Chromedriver → 配好 API Key三步你就能用自然語言指揮瀏覽器干活?,F(xiàn)在就去試試你的第一條指令吧【免費(fèi)下載鏈接】browserpilotNatural language browser automation項(xiàng)目地址: https://gitcode.com/gh_mirrors/br/browserpilot創(chuàng)作聲明:本文部分內(nèi)容由AI輔助生成(AIGC),僅供參考