Skip to content

proxy example #20

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions proxy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a package doc, like:

// Package main shows how to use chromedp via a proxy. In this case, we're connecting via SOCKS5 to a proxy running on port 9050 on the local machine.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would one use a socks5 proxy with auth?


import (
"context"
"fmt"
"log"

"github.com/chromedp/chromedp"
)

func main() {
ctx := context.Background()
options := []chromedp.ExecAllocatorOption{
chromedp.ProxyServer("socks5://127.0.0.1:9050"),
}
options = append(options, chromedp.DefaultExecAllocatorOptions[:]...)

c, cc := chromedp.NewExecAllocator(ctx, options...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actx, ctx := ...

defer cc()
// create context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

ctx, cancel := chromedp.NewContext(c)
defer cancel()
var res string
err := chromedp.Run(ctx,
chromedp.Navigate("https://2ip.ru"),
chromedp.Text(`#d_clip_button`, &res, chromedp.NodeVisible, chromedp.ByID))
if err != nil {
log.Fatal(err)
}
fmt.Println(res)
}