Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cplasfwst opened this issue Feb 26, 2024 · 3 comments
Labels
duplicate This issue or pull request already exists question Questions related to rod

Comments

@cplasfwst
Copy link

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 cplasfwst added the question Questions related to rod label Feb 26, 2024
Copy link

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

@cplasfwst
Copy link
Author

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?

@ysmood
Copy link
Collaborator

ysmood commented Feb 27, 2024

Please fix your markdown format first

@ysmood ysmood added the duplicate This issue or pull request already exists label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Questions related to rod
Projects
None yet
Development

No branches or pull requests

2 participants