# 自动脚本_超星学习通_go语言 **Repository Path**: lujin49/auto_study_chaoxing ## Basic Information - **Project Name**: 自动脚本_超星学习通_go语言 - **Description**: 利用 playwright-go 来开发的,自动学习"超星学习通" 网站 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-19 - **Last Updated**: 2026-11-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 使用GO开发playwright ## 优点: - go语言编译后, 用户无法看到源码,保密性高 - go语言编译后,运行效率高. - go语言编译后,体积小,占用内存少. ## 相关文档 - [playwright](https://playwright.nodejs.cn/docs/api/class-playwright) - [playwright-go](https://gitcode.com/gh_mirrors/pl/playwright-go/?index=top&type=card) - [go版playwright](https://pkg.go.dev/github.com/mxschmitt/playwright-go) - [playwright官方镜像](https://mcr.microsoft.com/en-us/artifact/mar/playwright) ## 安装 1. 需要安装go语言环境 2. 初始化项目 ```bash go mod init my-playwright ``` 3. 安装playwright-go ```bash go get -u github.com/mxschmitt/playwright-go ``` 在这个项目中的 go.mod 文件中,有关于 playwright-go 的版本信息, 可以通过 go.mod 文件中的版本信息, 来确定 playwright-go 的版本. 例如: ```bash require ( github.com/deckarep/golang-set/v2 v2.9.0 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/mxschmitt/playwright-go v0.6201.1 // indirect go.mongodb.org/mongo-driver v1.17.9 // indirect ) ``` 在下一步中,需要用到这个版本号, 所以需要记录下来. 4. 安装chromium(如果使用playwright镜像,但不需要执行这一步) 这一步中的 `0.xxxx.x` 就是上一步中的 `v0.6201.1` 中的 `0.6201.1` 部分. ```bash go run github.com/mxschmitt/playwright-go/cmd/playwright@v0.xxxx.x install --with-deps # Or go install github.com/mxschmitt/playwright-go/cmd/playwright@v0.xxxx.x playwright install --with-deps ``` ## 调试方法 CDP 连接已打开的真实浏览器(调试体验最好) ### 1. 手动启动 Chrome(带调试端口,用真实用户目录) ```bash # 1. 手动启动 Chrome(带调试端口,用真实用户目录) google-chrome --remote-debugging-port=9222 \ --user-data-dir=/home/lujin/.cache/chrome-debug-profile ``` # 2. 在里面手动登录一次,之后一直保持登录状态 ```go pw, err := playwright.Run() if err != nil { log.Fatalf("could not start playwright: %v", err) } browser, err := pw.Chromium.ConnectOverCDP("http://127.0.0.1:9222") context := browser.Contexts()[0] page := context.Pages()[0] // 直接操作已登录的页面 // 直接执行相关的页面的操作 playSection := playsection.NewPlaySection(page) playSection.Play() ```