Add cdp support for xpath scrapers (#625)

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
bnkai
2020-08-04 03:42:40 +03:00
committed by GitHub
parent 1b4a9eed36
commit 4373f9bf01
284 changed files with 133250 additions and 54 deletions

View File

@@ -0,0 +1,503 @@
// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.
package performance
import (
json "encoding/json"
easyjson "github.com/mailru/easyjson"
jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter"
)
// suppress unused package warning
var (
_ *json.RawMessage
_ *jlexer.Lexer
_ *jwriter.Writer
_ easyjson.Marshaler
)
func easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance(in *jlexer.Lexer, out *Metric) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "name":
out.Name = string(in.String())
case "value":
out.Value = float64(in.Float64())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance(out *jwriter.Writer, in Metric) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"name\":"
out.RawString(prefix[1:])
out.String(string(in.Name))
}
{
const prefix string = ",\"value\":"
out.RawString(prefix)
out.Float64(float64(in.Value))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v Metric) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Metric) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *Metric) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Metric) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance(l, v)
}
func easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance1(in *jlexer.Lexer, out *GetMetricsReturns) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "metrics":
if in.IsNull() {
in.Skip()
out.Metrics = nil
} else {
in.Delim('[')
if out.Metrics == nil {
if !in.IsDelim(']') {
out.Metrics = make([]*Metric, 0, 8)
} else {
out.Metrics = []*Metric{}
}
} else {
out.Metrics = (out.Metrics)[:0]
}
for !in.IsDelim(']') {
var v1 *Metric
if in.IsNull() {
in.Skip()
v1 = nil
} else {
if v1 == nil {
v1 = new(Metric)
}
(*v1).UnmarshalEasyJSON(in)
}
out.Metrics = append(out.Metrics, v1)
in.WantComma()
}
in.Delim(']')
}
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance1(out *jwriter.Writer, in GetMetricsReturns) {
out.RawByte('{')
first := true
_ = first
if len(in.Metrics) != 0 {
const prefix string = ",\"metrics\":"
first = false
out.RawString(prefix[1:])
{
out.RawByte('[')
for v2, v3 := range in.Metrics {
if v2 > 0 {
out.RawByte(',')
}
if v3 == nil {
out.RawString("null")
} else {
(*v3).MarshalEasyJSON(out)
}
}
out.RawByte(']')
}
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v GetMetricsReturns) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance1(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v GetMetricsReturns) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance1(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *GetMetricsReturns) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance1(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *GetMetricsReturns) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance1(l, v)
}
func easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance2(in *jlexer.Lexer, out *GetMetricsParams) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance2(out *jwriter.Writer, in GetMetricsParams) {
out.RawByte('{')
first := true
_ = first
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v GetMetricsParams) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance2(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v GetMetricsParams) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance2(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *GetMetricsParams) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance2(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *GetMetricsParams) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance2(l, v)
}
func easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance3(in *jlexer.Lexer, out *EventMetrics) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "metrics":
if in.IsNull() {
in.Skip()
out.Metrics = nil
} else {
in.Delim('[')
if out.Metrics == nil {
if !in.IsDelim(']') {
out.Metrics = make([]*Metric, 0, 8)
} else {
out.Metrics = []*Metric{}
}
} else {
out.Metrics = (out.Metrics)[:0]
}
for !in.IsDelim(']') {
var v4 *Metric
if in.IsNull() {
in.Skip()
v4 = nil
} else {
if v4 == nil {
v4 = new(Metric)
}
(*v4).UnmarshalEasyJSON(in)
}
out.Metrics = append(out.Metrics, v4)
in.WantComma()
}
in.Delim(']')
}
case "title":
out.Title = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance3(out *jwriter.Writer, in EventMetrics) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"metrics\":"
out.RawString(prefix[1:])
if in.Metrics == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v5, v6 := range in.Metrics {
if v5 > 0 {
out.RawByte(',')
}
if v6 == nil {
out.RawString("null")
} else {
(*v6).MarshalEasyJSON(out)
}
}
out.RawByte(']')
}
}
{
const prefix string = ",\"title\":"
out.RawString(prefix)
out.String(string(in.Title))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v EventMetrics) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance3(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v EventMetrics) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance3(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *EventMetrics) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance3(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *EventMetrics) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance3(l, v)
}
func easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance4(in *jlexer.Lexer, out *EnableParams) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "timeDomain":
(out.TimeDomain).UnmarshalEasyJSON(in)
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance4(out *jwriter.Writer, in EnableParams) {
out.RawByte('{')
first := true
_ = first
if in.TimeDomain != "" {
const prefix string = ",\"timeDomain\":"
first = false
out.RawString(prefix[1:])
(in.TimeDomain).MarshalEasyJSON(out)
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v EnableParams) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance4(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v EnableParams) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance4(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *EnableParams) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance4(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *EnableParams) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance4(l, v)
}
func easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance5(in *jlexer.Lexer, out *DisableParams) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance5(out *jwriter.Writer, in DisableParams) {
out.RawByte('{')
first := true
_ = first
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v DisableParams) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance5(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v DisableParams) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonC5a4559bEncodeGithubComChromedpCdprotoPerformance5(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *DisableParams) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance5(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *DisableParams) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonC5a4559bDecodeGithubComChromedpCdprotoPerformance5(l, v)
}

View File

@@ -0,0 +1,11 @@
package performance
// Code generated by cdproto-gen. DO NOT EDIT.
// EventMetrics current values of the metrics.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#event-metrics
type EventMetrics struct {
Metrics []*Metric `json:"metrics"` // Current values of the metrics.
Title string `json:"title"` // Timestamp title.
}

View File

@@ -0,0 +1,91 @@
// Package performance provides the Chrome DevTools Protocol
// commands, types, and events for the Performance domain.
//
// Generated by the cdproto-gen command.
package performance
// Code generated by cdproto-gen. DO NOT EDIT.
import (
"context"
"github.com/chromedp/cdproto/cdp"
)
// DisableParams disable collecting and reporting metrics.
type DisableParams struct{}
// Disable disable collecting and reporting metrics.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#method-disable
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes Performance.disable against the provided context.
func (p *DisableParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandDisable, nil, nil)
}
// EnableParams enable collecting and reporting metrics.
type EnableParams struct {
TimeDomain EnableTimeDomain `json:"timeDomain,omitempty"` // Time domain to use for collecting and reporting duration metrics.
}
// Enable enable collecting and reporting metrics.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#method-enable
//
// parameters:
func Enable() *EnableParams {
return &EnableParams{}
}
// WithTimeDomain time domain to use for collecting and reporting duration
// metrics.
func (p EnableParams) WithTimeDomain(timeDomain EnableTimeDomain) *EnableParams {
p.TimeDomain = timeDomain
return &p
}
// Do executes Performance.enable against the provided context.
func (p *EnableParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandEnable, p, nil)
}
// GetMetricsParams retrieve current values of run-time metrics.
type GetMetricsParams struct{}
// GetMetrics retrieve current values of run-time metrics.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#method-getMetrics
func GetMetrics() *GetMetricsParams {
return &GetMetricsParams{}
}
// GetMetricsReturns return values.
type GetMetricsReturns struct {
Metrics []*Metric `json:"metrics,omitempty"` // Current values for run-time metrics.
}
// Do executes Performance.getMetrics against the provided context.
//
// returns:
// metrics - Current values for run-time metrics.
func (p *GetMetricsParams) Do(ctx context.Context) (metrics []*Metric, err error) {
// execute
var res GetMetricsReturns
err = cdp.Execute(ctx, CommandGetMetrics, nil, &res)
if err != nil {
return nil, err
}
return res.Metrics, nil
}
// Command names.
const (
CommandDisable = "Performance.disable"
CommandEnable = "Performance.enable"
CommandGetMetrics = "Performance.getMetrics"
)

View File

@@ -0,0 +1,64 @@
package performance
// Code generated by cdproto-gen. DO NOT EDIT.
import (
"errors"
"github.com/mailru/easyjson"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
// Metric run-time execution metric.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#type-Metric
type Metric struct {
Name string `json:"name"` // Metric name.
Value float64 `json:"value"` // Metric value.
}
// EnableTimeDomain time domain to use for collecting and reporting duration
// metrics.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#method-enable
type EnableTimeDomain string
// String returns the EnableTimeDomain as string value.
func (t EnableTimeDomain) String() string {
return string(t)
}
// EnableTimeDomain values.
const (
EnableTimeDomainTimeTicks EnableTimeDomain = "timeTicks"
EnableTimeDomainThreadTicks EnableTimeDomain = "threadTicks"
)
// MarshalEasyJSON satisfies easyjson.Marshaler.
func (t EnableTimeDomain) MarshalEasyJSON(out *jwriter.Writer) {
out.String(string(t))
}
// MarshalJSON satisfies json.Marshaler.
func (t EnableTimeDomain) MarshalJSON() ([]byte, error) {
return easyjson.Marshal(t)
}
// UnmarshalEasyJSON satisfies easyjson.Unmarshaler.
func (t *EnableTimeDomain) UnmarshalEasyJSON(in *jlexer.Lexer) {
switch EnableTimeDomain(in.String()) {
case EnableTimeDomainTimeTicks:
*t = EnableTimeDomainTimeTicks
case EnableTimeDomainThreadTicks:
*t = EnableTimeDomainThreadTicks
default:
in.AddError(errors.New("unknown EnableTimeDomain value"))
}
}
// UnmarshalJSON satisfies json.Unmarshaler.
func (t *EnableTimeDomain) UnmarshalJSON(buf []byte) error {
return easyjson.Unmarshal(buf, t)
}