Advanced Guide

Làm Chủ Tự Động Hóa Trình Duyệt

Hướng dẫn đầy đủ để tự động hóa Nox Core với Puppeteer, Playwright và Selenium. Ví dụ mã sẵn sàng sản xuất và các thực hành tốt nhất.

Bắt Đầu Nhanh

Chạy trong 5 phút

Ví Dụ Mã

Đoạn mã sẵn sàng sao chép

Động Cơ RPA

Tự động hóa không cần mã

Code Examples

Puppeteer + Chrome DevTools Protocol

Connect to Nox Core via Chrome DevTools Protocol for full browser control.

Thiết Lập Cơ Bản
// 1. Launch Nox Core with remote debugging
// Add flag: --remote-debugging-port=9222

const puppeteer = require('puppeteer-core');

const browser = await puppeteer.connect({
  browserWSEndpoint: 'ws://localhost:9222',
  defaultViewport: null
});

const page = await browser.newPage();
await page.goto('https://example.com');
Tính Năng Nâng Cao
// Advanced profile management
const profileId = 'your-profile-id';

// Get all available targets
const targets = await browser.targets();
const pageTarget = targets.find(t => t.type() === 'page');

// Execute CDP commands
const client = await page.target().createCDPSession();

// Set custom user agent
await client.send('Network.setUserAgentOverride', {
  userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
});

// Block specific resources
await client.send('Network.setBlockedURLs', {
  urls: ['*.analytics.com', '*.tracking.js']
});
Mẫu Tự Động Hóa
// Automation best practices
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

// Human-like typing
async function humanType(page, selector, text) {
  for (const char of text) {
    await page.type(selector, char, { delay: Math.random() * 100 + 50 });
  }
}

// Random mouse movements
async function randomMove(page) {
  await page.mouse.move(
    Math.random() * 800 + 100,
    Math.random() * 600 + 100
  );
}

// Use in your script
await randomMove(page);
await humanType(page, '#username', 'john_doe');
await delay(Math.random() * 500 + 200);
await humanType(page, '#password', 'secret123');

Thực Hành Tốt Nhất

Tránh Phát Hiện

  • Sử dụng độ trễ thực tế giữa các hành động (200-1000ms)
  • Ngẫu nhiên hóa chuyển động chuột và vị trí nhấp
  • Thay đổi kích thước viewport và user agent
  • Xóa cookie và bộ nhớ giữa các phiên

Hiệu Suất

  • Tái sử dụng phiên bản trình duyệt khi có thể
  • Sử dụng chế độ headless để hiệu suất tốt hơn
  • Chặn tài nguyên không cần thiết
  • Triển khai connection pooling

Quản Lý Proxy

  • Xoay vòng proxy mỗi 10-20 yêu cầu
  • Khớp vị trí proxy với múi giờ
  • Kiểm tra chất lượng proxy trước khi sử dụng
  • Sử dụng proxy cư trú/ISP cho các trang nhạy cảm

Xử Lý Lỗi

  • Triển khai logic retry với exponential backoff
  • Chụp ảnh màn hình khi thất bại
  • Ghi lại tất cả hành động để gỡ lỗi
  • Xử lý CAPTCHA một cách duyên dáng

Ví Dụ Động Cơ RPA

Tự Động Hóa Đăng Nhập

Tự động hóa quy trình đăng nhập với hỗ trợ 2FA

// Nox Core RPA - Login Flow
{
  "steps": [
    { "action": "navigate", "url": "https://example.com/login" },
    { "action": "wait", "selector": "#username", "timeout": 5000 },
    { "action": "type", "selector": "#username", "value": "{{USERNAME}}" },
    { "action": "type", "selector": "#password", "value": "{{PASSWORD}}" },
    { "action": "click", "selector": "#login-btn" },
    { "action": "wait", "selector": ".dashboard", "timeout": 10000 },
    { "action": "extract", "selector": ".user-name", "variable": "loggedUser" }
  ]
}

Trích Xuất Dữ Liệu

Trích xuất dữ liệu từ nhiều trang

// Nox Core RPA - Data Extraction
{
  "steps": [
    { "action": "navigate", "url": "{{PRODUCT_URL}}" },
    { "action": "wait", "selector": ".product-title" },
    { "action": "extract", "selector": ".product-title", "variable": "title" },
    { "action": "extract", "selector": ".price", "variable": "price" },
    { "action": "extract", "selector": ".availability", "variable": "stock" },
    { "action": "screenshot", "name": "product_{{timestamp}}" },
    { "action": "webhook", "url": "{{API_ENDPOINT}}", "data": ["title", "price", "stock"] }
  ]
}

Gửi Biểu Mẫu

Tự động hóa gửi biểu mẫu phức tạp

// Nox Core RPA - Form Submission
{
  "steps": [
    { "action": "navigate", "url": "https://example.com/form" },
    { "action": "select", "selector": "#country", "value": "{{COUNTRY}}" },
    { "action": "type", "selector": "#fullname", "value": "{{FULLNAME}}" },
    { "action": "type", "selector": "#email", "value": "{{EMAIL}}" },
    { "action": "click", "selector": "#terms-checkbox" },
    { "action": "click", "selector": "#submit-btn" },
    { "action": "wait", "selector": ".success-message", "timeout": 15000 },
    { "action": "condition", "if": ".error", "then": [{ "action": "log", "message": "Submission failed" }] }
  ]
}

Thông Báo Quan Trọng

Luôn tôn trọng Điều Khoản Dịch Vụ của trang web khi tự động hóa. Sử dụng tự động hóa một cách có trách nhiệm và đảm bảo tuân thủ luật pháp và quy định địa phương.

Tài Nguyên Bổ Sung

Sẵn Sàng Tự Động Hóa?

Nhận giấy phép Nox Core và bắt đầu xây dựng quy trình làm việc tự động hóa mạnh mẽ ngay hôm nay.

Bắt Đầu