跳到主要内容

tophant.benjamin.x.entity

Messages

message AuthConfig

AuthConfig 为 tophant.benjamin.entity.AuthConfig 微调得到的 与其唯一区别是:auth_record 在 entity 中是 string,而在这里是 tophant.adam.AuthRecord

message AuthConfig {
bool enable = 1;
// adam 的服务器地址
string adam_host = 11;
// 传递给 adam 的登录配置文件
tophant.adam.AuthRecord auth_record = 21;
// TODO 其他传递给 adam 用于检查登录配置的配置
double check_interval_seconds = 31;
}

message AuthResult

AuthResult 始终与 tophant.benjamin.entity.AuthResult 保持一致

message AuthResult {
bool enable = 1;
repeated tophant.benjamin.Cookie cookies = 11;
repeated tophant.benjamin.Pair local_storage = 12;
repeated tophant.benjamin.Pair session_storage = 13;
// 动态爬虫不会读取该字段,可使用 RequestConfig 中的 custom_headers 来配置
repeated tophant.benjamin.Pair additional_headers = 14;
}

message ChromeConfig

ChromeConfig 始终与 tophant.benjamin.entity.ChromeConfig 保持一致

message ChromeConfig {
// Chrome 的版本,未来或许我们内置多版本的 Chrome 供自由选用;当前留空即可
string version = 1;
// 是否禁用无头模式,留空为否即启用无头模式(不会打开浏览器窗口)
bool no_headless = 2;
// 是否启用无痕模式,默认为不启用【暂不支持该功能】
bool incognito_context = 3;
int64 viewport_width = 4;
int64 viewport_height = 5;
// 自定义配置
}

message CustomScriptsConfig

message CustomScriptsConfig {
bool enable = 1;
repeated tophant.benjamin.CustomScript evaluate_on_new_documents = 11;
repeated tophant.benjamin.CustomScript evaluate_after_dom_ready = 12;
}

message DebugConfig

message DebugConfig {
// 开启 debug 模式(注意:该功能仅用于给单独任务开启 debug,如果全局开启了 debug 无法在任务维度关闭)
bool enable = 101;
// 是否开启重放
bool enable_replay = 11;
// 是否持久化 Target 数据
bool enable_target_data_persistence = 12;
// 是否持久化 Result 数据
bool enable_result_data_persistence = 13;
// 是否开启 Sentry
bool enable_sentry = 14;
string sentry_dsn = 2;
// 请使用 enable_replay
bool disable_rrweb = 1;
}

message DeviceEmulationConfig

message DeviceEmulationConfig {
// 是否开启设备模拟
bool enable = 1;
bool rotate90 = 12;
bool mobile = 21;
bool touch = 22;
}

message DeviceEmulationConfig.Screen

message Screen {
uint32 width = 1;
uint32 height = 2;
double device_pixel_ratio = 3;
}

message ElementHandleConfig

ElementHandleConfig 始终与 tophant.benjamin.entity.ElementHandleConfig 保持一致

message ElementHandleConfig {
bool enable = 1;
// 忽略新增的元素
bool ignore_new_elements = 2;
// 处理的元素列表,默认为 ['a', 'input', 'button', 'form', 'select', 'td', 'area', 'img', 'iframe', 'li', 'span', 'i']
repeated string elements = 21;
// 每处理一个元素之后, 尝试新元素次数,默认 0 为自动控制
uint32 try_new_elements_count = 31;
// 每次尝试新元素之前的等待时间,单位为秒,默认为 0 为自动控制
double wait_before_try_new_elements_seconds = 32;
// 点击任意元素,默认为 false
bool click_any_element = 33;
// 等待指定时间之后再处理下一个元素, 该时间会影响对新产生元素的处理, 加大可以多处理新产生的元素,单位为秒,默认为 0 为自动控制
double wait_before_handle_next_element_seconds = 34;
}

message EventHandleConfig

EventHandleConfig 始终与 tophant.benjamin.entity.EventHandleConfig 保持一致

message EventHandleConfig {
bool enable = 1;
}
message ExternalLink {
string task_id = 1;
string task_job_id = 2;
int32 task_iterate = 3;
string parent_target_id = 4;
string url = 11;
string canonical_url = 12;
}

message ExtraAuthConfig

ExtraAuthConfig 始终与 tophant.benjamin.entity.ExtraAuthConfig 保持一致

message ExtraAuthConfig {
// 用于支持浏览器侧的认证(Basic Auth & Digest Auth)
tophant.benjamin.BrowserAuth browser_auth = 2;
// BasicAuth 认证后续会被废弃,建议切换为使用 BrowserAuth
}

message FollowPolicy

message FollowPolicy {
oneof policy {
FollowPolicy.SameTLD same_tld = 1;
FollowPolicy.SameDomain same_domain = 2;
FollowPolicy.SameDir same_dir = 3;
FollowPolicy.SameSLD same_sld = 4;
bool any = 99;
}
}

message FollowPolicy.SameDir

message SameDir {
string domain = 1;
repeated string extra_domains = 3;
string dir = 2;
bool ignore_port = 11;
}

message FollowPolicy.SameDomain

message SameDomain {
string domain = 1;
repeated string extra_domains = 2;
bool ignore_port = 11;
}

message FollowPolicy.SameSLD

message SameSLD {
string sld = 1;
string port = 2;
bool ignore_port = 11;
}

message FollowPolicy.SameTLD

message SameTLD {
string domain_suffix = 1;
repeated string extra_domain_suffixes = 2;
bool ignore_port = 11;
}

message Manager

message Manager {
// manager 的连接信息
string host = 1;
// 心跳时间
google.protobuf.Timestamp tick = 21;
// 创建时间
google.protobuf.Timestamp created_at = 22;
}

message NetworkConfig

NetworkConfig 始终与 tophant.benjamin.entity.NetworkConfig 保持一致

message NetworkConfig {
// 上游代理
string upstream_proxy = 21;
}

message RemoveElementsConfig

RemoveElementsConfig 始终与 tophant.benjamin.entity.RemoveElementsConfig 保持一致

message RemoveElementsConfig {
bool enable = 1;
repeated tophant.benjamin.RemoveElement remove_elements = 2;
}

message RequestBlockConfig

message RequestBlockConfig {
bool enable = 1;
bool allow_static_files = 11;
// 针对请求方法的特殊处理
map<string,bool> block_methods = 12;
}

message RequestConfig

RequestConfig 与 tophant.benjamin.entity.RequestConfig 保持一致

message RequestConfig {
string user_agent = 1;
string accept_language = 4;
string referer = 2;
// 指定自定义 headers
// 该参数会适用于页面上的所有请求,在几乎任何情况下均不建议使用
// 为了防止异常行为,如果在这里指定如下 header 会报错:
// "connection", "content-length", "cookie", "host", "user-agent"
repeated tophant.benjamin.Pair custom_headers = 9;
repeated tophant.benjamin.Pair cookies = 3;
repeated tophant.benjamin.Pair local_storage = 11;
repeated tophant.benjamin.Pair session_storage = 12;
// 超时时间配置
//
// 单页面爬取的最大时间,单位为秒,默认 0 为自动控制
double single_page_timeout_seconds = 21;
// 页面打开的超时时间,单位为秒,默认 0 为自动控制
double open_page_timeout_seconds = 22;
// 操作进程时间配置
//
// 在已经确认页面加载完成到进行页面处理的等待时间,单位为秒,默认 0 为自动控制
double wait_after_open_page_seconds = 31;
// 在处理完所有页面到关闭网页的处理的等待时间,单位为秒,默认 0 为自动控制
double wait_before_close_page_seconds = 32;
// 两个处理步骤之间的等待时间,单位为秒,默认 0 为自动控制 TODO 暂时无效
double wait_between_handle_steps_seconds = 33;
// 位置模拟配置
//
// 是否开启位置模拟
bool enable_emulate_location = 51;
// 模拟纬度
double location_latitude = 52;
// 模拟经度
double location_longitude = 53;
}

message Result

message Result {
}

message ScreenshotConfig

message ScreenshotConfig {
}

message StorageConfig

StorageConfig 始终与 tophant.benjamin.entity.StorageConfig 保持一致

message StorageConfig {
// 最大保存多大的资源 body, 单位为 Bytes,默认限制为 10MB
int64 collect_body_size_limit_bytes = 1;
// 对于 Documents/XHR/Fetch 的存储大小分界线(小于等于该值存储为 Raw,否则为 Local/OSS)
int64 collect_body_size_dividing_normal_bytes = 11;
// 对于静态资源(Stylesheet/Image/Media/Font/Script/TextTrack)的存储大小分界线(小于等于该值存储为 Raw,否则为 Local/OSS)
int64 collect_body_size_dividing_static_bytes = 12;
// 对于其他资源的存储大小分界线(小于等于该值存储为 Raw,否则为 Local/OSS)
int64 collect_body_size_dividing_other_bytes = 13;
// Raw 最大保存多大的资源 body, 单位为 Bytes,超出该值会被截断,默认限制为 10MB
int64 raw_body_size_limit_bytes = 21;
// Local 最大保存多大的资源 body, 单位为 Bytes,超出该值会被截断,默认为不限制
int64 local_body_size_limit_bytes = 31;
// OSS 最大保存多大的资源 body, 单位为 Bytes,超出该值会被截断,默认为不限制
int64 oss_body_size_limit_bytes = 41;
// RRWeb 数据的存储策略
tophant.benjamin.StoragePolicy rrweb_storage_policy = 71;
// 截图数据的存储策略
tophant.benjamin.StoragePolicy screenshot_storage_policy = 72;
// OSS 配置
}

message Target

message Target {
TargetConfig config = 2;
}

message TargetConfig

message TargetConfig {
NetworkConfig network_config = 5;
DeviceEmulationConfig device_emulation_config = 13;
RequestConfig request_config = 1;
StorageConfig storage_config = 7;
ElementHandleConfig element_handle_config = 2;
EventHandleConfig event_handle_config = 4;
AuthResult auth_result = 3;
ExtraAuthConfig extra_auth_config = 6;
CustomScriptsConfig custom_scripts = 9;
RemoveElementsConfig remove_elements = 14;
tophant.benjamin.FormFillConfig form_fill_config = 12;
// 应当截图
bool should_take_screenshot = 10;
DebugConfig debug_config = 11;
repeated string flags = 99;
}

message TargetDebug

message TargetDebug {
google.protobuf.Timestamp time = 1;
string target_id = 2;
string key = 3;
// Added for tracking which task created this debug entry
string task_id = 10;
string key1 = 11;
string key2 = 12;
string key3 = 13;
string key4 = 14;
string key5 = 15;
// must be json
bytes data = 21;
// 只读
int32 id = 31;
}

message Task

message Task {
TaskConfig config = 2;
// 任务所在的 manager
Manager manager = 12;
// 任务所拥有的 worker
repeated Worker workers = 13;
}

message TaskConfig

message TaskConfig {
// 初始 URL 列表
repeated string entry_points = 1;
// 强制重新爬取列表,仅在更新任务配置时有效
repeated string force_entry_points = 6;
repeated TaskConfig_Site sites = 2;
// 并发配置
TaskConfig_Concurrency concurrency = 3;
// 外部数据源配置
TaskConfig_External external = 4;
// 结果限制
TaskConfig_Limit limit = 5;
// 浏览器配置
ChromeConfig chrome = 11;
// 设备模拟配置
DeviceEmulationConfig device_emulation_config = 10;
// 网络配置
NetworkConfig network_config = 16;
// 爬取过程配置
RequestConfig request_config = 12;
StorageConfig storage_config = 13;
AuthConfig auth_config = 14;
AuthResult auth_result = 15;
ExtraAuthConfig extra_auth_config = 17;
ScreenshotConfig screenshot_config = 18;
DebugConfig debug_config = 19;
tophant.benjamin.FormFillConfig form_fill_config = 20;
// 输出配置
repeated TaskConfig_Output output = 51;
// 子进程启动方式
TaskConfig_SubProcessPolicy subprocess_policy = 61;
// 创建任务时的全局配置
ElementHandleConfig element_handle_config = 71;
EventHandleConfig event_handle_config = 72;
RequestBlockConfig request_block_config = 76;
tophant.benjamin.CustomScriptsConfig custom_scripts_config = 81;
RemoveElementsConfig remove_elements_config = 82;
repeated string flags = 97;
// 外部请求时传递的配置参数
// 增量修改配置时外部请求时传递的配置参数
repeated tophant.benjamin.UpdateTaskConfig updates = 98;
}

message TaskConfig_Concurrency

message TaskConfig_Concurrency {
int64 browser_concurrency = 1;
int64 tab_concurrency = 2;
}

message TaskConfig_External

message TaskConfig_External {
bool robots_txt = 1;
bool sitemap = 2;
}

message TaskConfig_Limit

message TaskConfig_Limit {
// 爬取范围限制
//
// 最大爬取层级,默认为 999【仅用于防止死循环】
int64 max_depth = 11;
// 结果情况限制
//
// 最大的爬取目标数(默认 0 不限制)(非精准限制)
int64 max_target = 41;
// 最大的记录结果数(默认 0 不限制)(非精准限制)
int64 max_result = 42;
// 爬取时间限制
//
// 最大的爬取时间(单位为秒,默认 0 不限制)(非精准限制)
int64 max_time_seconds = 43;
}

message TaskConfig_Output

message TaskConfig_Output {
}

message TaskConfig_Site

message TaskConfig_Site {
string url = 1;
FollowPolicy follow_policy = 2;
}

message TaskConfig_SubProcessPolicy

message TaskConfig_SubProcessPolicy {
oneof policy {
// 直接启动一个 GoRoutine 来执行任务
bool coroutine = 1;
// 启动一个子进程来执行任务
bool subprocess = 2;
// 利用 docker 来执行任务 TODO P2
// 利用 k8s 来执行任务 TODO P9
}
}

message TaskConfig_SubProcessPolicy.Docker

message Docker {
string image = 1;
string api_host = 2;
}

message TaskConfig_SubProcessPolicy.Kubernetes

TODO P9

message Kubernetes {
// no fields
}

message Worker

message Worker {
// worker 的 UUID
string id = 1;
// worker 的名称
string name = 2;
// worker 的 hostname(可能为真实或容器中的虚拟 hostname)
string hostname = 4;
// worker 的 tag,目前仅为 priority 或 normal
repeated string tags = 3;
// worker 所属的浏览器的连接信息
string browser_control_url = 11;
// 心跳时间
google.protobuf.Timestamp tick = 21;
// 创建时间
google.protobuf.Timestamp created_at = 22;
}