# 代码
```go
const (
seleniumPath = `D:/download/1/chromedriver.exe`
port = 9999
)
var options []selenium.ServiceOption
service, err2 := selenium.NewChromeDriverService(seleniumPath, port, options...)
common.Must(err2)
chromeCaps := chrome.Capabilities{
Path: "",
Args: []string{
//"--headless", // 设置Chrome无头模式,在linux下运行,需要设置这个参数,否则会报错
//"--no-sandbox",
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36", // 模拟user-agent,防反爬
},
}
//以上是设置浏览器参数
caps := selenium.Capabilities{"browserName": "chrome"}
caps.AddChrome(chromeCaps)
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://127.0.0.1:%d/wd/hub", port))
common.Must(err)
defer func() {
common.Must(service.Stop())
common.Must(wd.Close())
common.Must(wd.Quit())
}()
err3 := wd.Get("https://baidu.com")
common.Must(err3)
```
![屏幕截图 2021-03-12 222832.jpg](https://static.studygolang.com/210312/81f0cb6e93480fc0fc1b23a65478addd.jpg)
有疑问加站长微信联系(非本文作者)