pub struct Response {
pub url: String,
pub status: u16,
pub headers: HashMap<String, String>,
pub body: String,
}Expand description
统一的 HTTP 响应结构
无论底层使用 reqwest、wreq 还是 Chrome,都统一转换为该类型。
Fields§
§url: String最终请求的 URL(可能经过重定向)
status: u16HTTP 状态码
headers: HashMap<String, String>响应头
body: String响应体(文本)
Implementations§
Source§impl Response
impl Response
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
状态码是否为 2xx
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
获取 Content-Type
Sourcepub fn is_html(&self) -> bool
pub fn is_html(&self) -> bool
是否为 HTML 内容
匹配 text/html、application/xhtml+xml,或 body 以 <!doctype html / <html 开头。
Sourcepub fn is_bot_challenge(&self) -> bool
pub fn is_bot_challenge(&self) -> bool
检测响应是否为机器人验证页面
很多反爬服务(PerimeterX、Cloudflare、DataDome、Akamai 等)在检测到爬虫时 返回 HTTP 200,但 body 内容是 CAPTCHA/challenge 页面,不是真实内容。 此方法通过检测 body 中的特征关键词来识别这类伪成功响应。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more