rod icon indicating copy to clipboard operation
rod copied to clipboard

Dear go-rod production team, I would like to ask you a question about remote connections and using proxies.

Open cplasfwst opened this issue 5 months ago • 3 comments

Rod Version: v0.114.7

The code to demonstrate your question

Question 1: I use the official code: docker run -p 7317:7317 ghcr.io/go-rod/rod Create a remote rod service If I connect like this: `func playwa1(hello *widget.TextGrid) string { u := launcher.MustResolveURL("192.168.1.29:7317") //How do I use a proxy?

browser := rod.New().ControlURL(u).MustConnect()

s := browser.MustPage("https://ip138.com/").MustEval("() => document.title").String()

browser.ServeMonitor(":7779")

//time.Sleep(60 * time.Second)

return s

}`

How do I use a proxy?

Later I used test scenario 2: Server: `// A server to help launch browser remotely package main

import ( "flag" "fmt" "log" "net" "net/http" "os"

"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/utils"

)

var ( addr = flag.String("address", ":7311", "the address to listen to") quiet = flag.Bool("quiet", false, "silence the log") allowAllPath = flag.Bool("allow-all", false, "allow all path set by the client") )

func main() { flag.Parse()

m := launcher.NewManager()

if !*quiet {
	m.Logger = log.New(os.Stdout, "", 0)
}

if *allowAllPath {
	m.BeforeLaunch = func(l *launcher.Launcher, _ http.ResponseWriter, _ *http.Request) {
		l.Proxy(`p32.gdsg4.jyip.net`)
	}
}

l, err := net.Listen("tcp", *addr)
if err != nil {
	utils.E(err)
}

if !*quiet {
	fmt.Println("[rod-manager] listening on:", l.Addr().String())
}

srv := &http.Server{Handler: m}
utils.E(srv.Serve(l))

} My client:func playwa1(hello *widget.TextGrid) string { u := launcher.MustResolveURL("192.168.1.29:7311")

browser := rod.New().ControlURL(u).MustConnect()
//go browser.MustHandleAuth(`st037260028`, `123456`)() // <-- 注意 HandleAuth 返回的
go browser.MustHandleAuth(`st037260028`, `123456`)() // <-- 注意 HandleAuth 返回的

b := browser.MustPage("https://zh-hans.ipshu.com/")

s := b.MustEval("() => document.title").String()

//b.MustElementX(`//span[@class="ip_copy pointer"]`)
text := b.MustElementX(`/html/body/div[1]/div[1]/div[2]/div/ul/li[1]/p/a`).MustText()

browser.ServeMonitor(":7779")

//time.Sleep(60 * time.Second)

fmt.Println("这里是输出", text)
return s

}`

Now I mainly hope that when the client uses rod, proxy can be used correctly. How should I solve it?

cplasfwst avatar Feb 26 '24 09:02 cplasfwst

Please fix the format of your markdown:

2 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "## The code to demonstrate your question"]
20 MD003/heading-style/header-style Heading style [Expected: atx; Actual: setext]
20 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "}`"]
22 MD003/heading-style/header-style Heading style [Expected: atx; Actual: setext]
22 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "How do I use a proxy?"]

generated by check-issue

github-actions[bot] avatar Feb 26 '24 09:02 github-actions[bot]

Because when I need remote crawling, I want each browser or each page to have a different IP address. How should I deal with it?

cplasfwst avatar Feb 26 '24 09:02 cplasfwst

Please fix your markdown format first

ysmood avatar Feb 27 '24 03:02 ysmood