Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Go library for managing browser instances with rod, supporting pooling, headless mode, proxies, cookies, and auto timeout.

NotificationsYou must be signed in to change notification settings

simp-lee/browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package provides a high-level API for managing and interacting with browser instances using therod library. It supports features such as browser pooling, headless mode, proxy configuration, cookies, and automatic idle timeout.

Installation

To install the package, usego get:

go get -u github.com/simp-lee/browser

Usage

Basic Usage

Here's a basic example of how to use the package:

package mainimport ("fmt""github.com/simp-lee/browser""time")funcmain() {// Get a browser instance with default optionsb,err:=browser.GetBrowser()iferr!=nil {panic(err)}deferb.Close()// Get a page instance from the browserpage,err:=b.GetPage()iferr!=nil {panic(err)}deferb.PutPage(page)page.MustNavigate("https://example.com")fmt.Println(page.MustInfo().Title)}

Configuring Browser Options

You can configure various options for the browser instance:

package mainimport ("github.com/simp-lee/browser""time")funcmain() {// Get a browser instance with custom optionsb,err:=browser.GetBrowser(browser.WithHeadless(false),browser.WithProxy("127.0.0.1:8080"),browser.WithPoolSize(5),browser.WithIdleTimeout(10*time.Minute),)iferr!=nil {panic(err)}deferb.Close()}

Configuring Page Options

You can configure various options for the page instance:

package mainimport ("fmt""github.com/simp-lee/browser")funcmain() {// Get a browser instance with default optionsb,err:=browser.GetBrowser()iferr!=nil {panic(err)}deferb.Close()// Get a page instance with custom optionspage,err:=b.GetPage(browser.WithUserAgent("CustomUserAgent"),browser.WithReferer("https://example.com"),browser.WithViewport(1920,1080,1.0,false),browser.WithExtraHeaders(map[string]string{"X-Custom-Header":"custom_value",}),browser.WithCookies(browser.Cookie{Name:"example_cookie",Value:"cookie_value",Domain:"example.com",}),)iferr!=nil {panic(err)}deferb.PutPage(page)page.MustNavigate("https://example.com")fmt.Println(page.MustInfo().Title)}

Blocking Image Loading

You can block image loading on a page by callingb.BlockImageLoading(page) to save bandwidth`:

package mainimport ("fmt""github.com/simp-lee/browser")funcmain() {// Get a browser instance with default optionsb,err:=browser.GetBrowser()iferr!=nil {panic(err)}deferb.Close()// Get a page instance from the browserpage,err:=b.GetPage()iferr!=nil {panic(err)}deferb.PutPage(page)// Block image loading on the pageiferr:=b.BlockImageLoading(page);err!=nil {panic(err)}page.MustNavigate("https://example.com")fmt.Println(page.MustInfo().Title)}

Retrieving Cookies

You can retrieve cookies from a page instance using theGetCookies method::

package mainimport ("fmt""github.com/simp-lee/browser")funcmain() {// Get a browser instance with default optionsb,err:=browser.GetBrowser()iferr!=nil {panic(err)}deferb.Close()// Get a page instance from the browserpage,err:=b.GetPage()iferr!=nil {panic(err)}deferb.PutPage(page)// Navigate to a URLpage.MustNavigate("https://example.com")// Get cookies from the pagecookies,err:=b.GetCookies(page)iferr!=nil {panic(err)}// Print the cookiesfor_,cookie:=rangecookies {fmt.Printf("Cookie: %+v\n",cookie)}}

About

A Go library for managing browser instances with rod, supporting pooling, headless mode, proxies, cookies, and auto timeout.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2026 Movatter.jp