Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tools
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
tools
Commits
172d081b
Commit
172d081b
authored
Jan 28, 2021
by
庄欣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image search image docker config
parent
891ac4ed
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
143 deletions
+0
-143
t2/go.mod
+0
-8
t2/go.sum
+0
-24
t2/main.go
+0
-111
No files found.
t2/go.mod
deleted
100644 → 0
View file @
891ac4ed
module example.com/m/v2
go 1.15
require (
github.com/PuerkitoBio/goquery v1.6.1 // indirect
github.com/chromedp/chromedp v0.6.4
)
t2/go.sum
deleted
100644 → 0
View file @
891ac4ed
github.com/PuerkitoBio/goquery v1.6.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/chromedp/cdproto v0.0.0-20210113043257-dabd2f2e7693 h1:11eq/RkpaotwdF6b1TRMcdgQUPNmyFEJOB7zLvh0O/Y=
github.com/chromedp/cdproto v0.0.0-20210113043257-dabd2f2e7693/go.mod h1:55pim6Ht4LJKdVLlyFJV/g++HsEA1hQxPbB5JyNdZC0=
github.com/chromedp/chromedp v0.6.4 h1:Gx7ZkRyrSVmbbDDja/ieNgNGJIvElroPOyeqYQGVDSY=
github.com/chromedp/chromedp v0.6.4/go.mod h1:vodUdJf5dF/b8n0UBJv6NeM/QK28RjP3j+eM7fq4+84=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs=
github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
t2/main.go
deleted
100644 → 0
View file @
891ac4ed
package
main
import
(
"context"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"time"
"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/cdproto/network"
"github.com/chromedp/chromedp"
)
var
flagPort
=
flag
.
Int
(
"port"
,
8544
,
"port"
)
func
main
()
{
flag
.
Parse
()
// start cookie server
go
cookieServer
(
fmt
.
Sprintf
(
":%d"
,
*
flagPort
))
// create context
ctx
,
cancel
:=
chromedp
.
NewContext
(
context
.
Background
())
defer
cancel
()
// run task list
var
res
string
err
:=
chromedp
.
Run
(
ctx
,
setcookies
(
fmt
.
Sprintf
(
"http://localhost:%d"
,
*
flagPort
),
&
res
,
"cookie1"
,
"value1"
,
"cookie2"
,
"value2"
,
))
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
log
.
Printf
(
"chrome received cookies: %s"
,
res
)
}
// cookieServer creates a simple HTTP server that logs any passed cookies.
func
cookieServer
(
addr
string
)
error
{
mux
:=
http
.
NewServeMux
()
mux
.
HandleFunc
(
"/"
,
func
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
cookies
:=
req
.
Cookies
()
for
i
,
cookie
:=
range
cookies
{
log
.
Printf
(
"from %s, server received cookie %d: %v"
,
req
.
RemoteAddr
,
i
,
cookie
)
}
buf
,
err
:=
json
.
MarshalIndent
(
req
.
Cookies
(),
""
,
" "
)
if
err
!=
nil
{
http
.
Error
(
res
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
fmt
.
Fprintf
(
res
,
indexHTML
,
string
(
buf
))
})
return
http
.
ListenAndServe
(
addr
,
mux
)
}
// setcookies returns a task to navigate to a host with the passed cookies set
// on the network request.
func
setcookies
(
host
string
,
res
*
string
,
cookies
...
string
)
chromedp
.
Tasks
{
if
len
(
cookies
)
%
2
!=
0
{
panic
(
"length of cookies must be divisible by 2"
)
}
return
chromedp
.
Tasks
{
chromedp
.
ActionFunc
(
func
(
ctx
context
.
Context
)
error
{
// create cookie expiration
expr
:=
cdp
.
TimeSinceEpoch
(
time
.
Now
()
.
Add
(
180
*
24
*
time
.
Hour
))
// add cookies to chrome
for
i
:=
0
;
i
<
len
(
cookies
);
i
+=
2
{
err
:=
network
.
SetCookie
(
cookies
[
i
],
cookies
[
i
+
1
])
.
WithExpires
(
&
expr
)
.
WithDomain
(
"localhost"
)
.
WithHTTPOnly
(
true
)
.
Do
(
ctx
)
if
err
!=
nil
{
return
err
}
}
return
nil
}),
// navigate to site
chromedp
.
Navigate
(
host
),
// read the returned values
chromedp
.
Text
(
`#result`
,
res
,
chromedp
.
ByID
,
chromedp
.
NodeVisible
),
// read network values
chromedp
.
ActionFunc
(
func
(
ctx
context
.
Context
)
error
{
fmt
.
Println
(
"111111111111111111111111111111111111111111111111111111111111111111111111"
)
cookies
,
err
:=
network
.
GetAllCookies
()
.
Do
(
ctx
)
if
err
!=
nil
{
return
err
}
for
i
,
cookie
:=
range
cookies
{
log
.
Printf
(
"chrome cookie %d: %+v"
,
i
,
cookie
)
}
return
nil
}),
}
}
const
(
indexHTML
=
`<!doctype html>
<html>
<body>
<div id="result">%s</div>
</body>
</html>`
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment