写go 调用Playwright时,遇到 could not start Playwright: please install the driver (v1.45.1) and browsers first: %!w(<nil>) 报错
解决方式:安装驱动和浏览器依赖。
go run github.com/playwright-community/playwright-go/cmd/playwright install --with-deps
测试代码:
package mainimport ("fmt""log""github.com/playwright-community/playwright-go" )func main() {pw, err := playwright.Run()if err != nil {log.Fatalf("could not start Playwright: %v", err)}defer pw.Stop()browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: playwright.Bool(true),})if err != nil {log.Fatalf("could not launch browser: %v", err)}defer browser.Close()page, err := browser.NewPage()if err != nil {log.Fatalf("could not create page: %v", err)}_, err = page.Goto("https://playwright.dev")if err != nil {log.Fatalf("could not go to page: %v", err)}title, err := page.Title()if err != nil {log.Fatalf("could not get page title: %v", err)}fmt.Println("Page title:", title) }
运行成功!!!