2024-07-10
爬虫
00

爬虫项目实战

Star History

Star History Chart

2025-12-10
爬虫
00

JS协议

定位业务接口

爬虫的第一步是定位目标接口,在浏览器采集的时候,常用的抓包方式有两种:

使用devtools

chrome,edge,safari,firefox等主流浏览器都自带了浏览器调试工具,通过f12等方式可以打开调试工具,打开network面板即可获取到所有数据流,从中筛选出对应的接口即可。

此方案可能遇到的风控:

打开调试工具会有明显的标志位,例如console.debug等检测,遇到强风控的网站可能会直接触发风控,常见风控表现例如无限debugger以及登录和验证码页面。

解决方案:

  1. 魔改浏览器内核,解决检测点。
  2. 定位到对方检测位置,将代码重写覆盖绕过检测。
  3. 使用无法被检测的浏览器调试。

使用抓包工具

可以使用小黄鸟,茶壶以及mitproxy等工具进行全局抓包获取所有数据流,从中筛选出目前接口。

此方案可能遇到的风控:

抓包软件的tls指纹和浏览器不同,遇到强风控的网站可能会直接触发风控。

解决方案:

自写抓包工具,魔改tls指纹通过检测。

获取数据

对于在接口没有设置风控参数以及风控逻辑的网站,找到目标接口就可以直接编写代码获取数据。

2025-12-10
爬虫
00

爬虫的定义和分类

什么是爬虫

爬虫是一种自动获取网络信息的程序,它模拟人类浏览的行为,按照一定的规则,从互联网上抓取数据。

爬虫的分类

  1. 从数据源来分 a. web爬虫 b. 移动爬虫
  2. 从爬取方式来分 a. 自动化爬虫 b. 协议爬虫

链路设计

  1. 明确目标:确定要爬取的网站、数据类型(如文本、图片、视频等)以及数据的用途。
  2. 明确接口:确定要爬取的业务接口(api,html,websocket...)
  3. 分析风控:业务接口签名,反爬措施(定制型,通用型)
  4. 编写脚本:模拟真实业务场景发送请求获取数据,解析数据
  5. 数据落地:清洗爬取到的数据,存入数据库
2025-07-19
自动化
00
javascript
/** * 统一检测当前页面是否运行在自动化/爬虫/测试环境 * 返回:非空字符串即表示检测到可疑特征,字符串内容即为命中详情 */ function detectAutomationEnvironment() { // 1. 可疑的全局对象名 const SUSPICIOUS_WINDOW_PROPS = [ '_phantom', '__nightmare', '_selenium', 'callPhantom', 'callSelenium', '_Selenium_IDE_Recorder', '__fxdriver_unwrapped', 'fxdriver_id', 'webdriver', 'domAutomation', 'Buffer', 'emit', 'spawn', 'fmget_targets' ]; // 2. 可疑的 document 属性(旧版 webdriver/selenium 遗留) const SUSPICIOUS_DOC_PROPS = [ '__webdriver_evaluate', '__selenium_evaluate', '__webdriver_script_function', '__webdriver_script_func', '__webdriver_script_fn', '__fxdriver_evaluate', '__driver_unwrapped', '__webdriver_unwrapped', '__driver_evaluate', '__selenium_unwrapped', '__fxdriver_unwrapped' ]; // 3. 正则:UA 包含 Headless/Phantom const UA_RE = /Headless|Phantom/i; // 4. 正则:Navigator 属性名里包含 dive(某些旧检测库) const NAV_PROP_RE = /dive/i; let evidence = ''; // 收集所有命中的线索 /* ---------- 1. 检测全局对象 ---------- */ SUSPICIOUS_WINDOW_PROPS.forEach(prop => { if (window[prop] !== undefined) evidence += `window.${prop};`; }); // Cypress 比较特殊,单独判断 if ('Cypress' in window) evidence += 'window.Cypress;'; /* ---------- 2. 检测 document 上的遗留属性 ---------- */ SUSPICIOUS_DOC_PROPS.forEach(prop => { if (document[prop] !== undefined) evidence += `document.${prop};`; }); // 检测形如 $cdc_... 的旧版缓存对象 Object.getOwnPropertyNames(document).forEach(prop => { if (/\$[a-z]dc_/.test(prop) && document[prop] && document[prop].cache_) { evidence += `document.${prop}.cache_;`; } }); /* ---------- 3. 检测 html 标签上的属性 ---------- */ const htmlAttrs = ['selenium', 'webdriver', 'driver']; htmlAttrs.forEach(attr => { if (document.documentElement.hasAttribute(attr)) { evidence += `htmlElement.hasAttribute(${attr});`; } }); /* ---------- 4. 检测 navigator.webdriver 标志 ---------- */ if (navigator.webdriver !== undefined) { evidence += `navigator.webdriver=${navigator.webdriver.toString().slice(0, 50)};`; } /* ---------- 5. 检测 UA 中的 Headless/Phantom ---------- */ if (UA_RE.test(navigator.userAgent)) { evidence += 'ua contains Headless|Phantom;'; } /* ---------- 6. 检测 navigator 属性名里是否含 dive ---------- */ try { let proto = navigator; while (proto) { Object.getOwnPropertyNames(proto).forEach(prop => { if (NAV_PROP_RE.test(prop)) evidence += `navigator key:${prop};`; }); proto = Object.getPrototypeOf(proto); } } catch (_) { // 忽略异常 } /* ---------- 7. 检测 Sequentum(少见) ---------- */ if (window.external && window.external.toString) { const extStr = window.external.toString(); if (extStr.includes('Sequentum')) { evidence += `window.external.toString()=${extStr.slice(0, 50)};`; } } return evidence; }
2025-07-19
爬虫
00

1 验证码类型分类

1.1 分类标准

验证码按用户交互复杂度可分为两大类:

1.1.1 有感验证码

需要用户完成特定验证任务,包括:

  • 文本识别验证码
  • 滑块距离识别验证码
  • 空间图形推理验证码
  • 联合推理验证码
  • 等等