Advanced Guide

เชี่ยวชาญการทำงานอัตโนมัติของเบราว์เซอร์

คู่มือฉบับสมบูรณ์สำหรับการทำงานอัตโนมัติของ Nox Core ด้วย Puppeteer, Playwright และ Selenium ตัวอย่างโค้ดพร้อมใช้งานและแนวทางปฏิบัติที่ดีที่สุด

เริ่มต้นใช้งานอย่างรวดเร็ว

เริ่มทำงานใน 5 นาที

ตัวอย่างโค้ด

สนิปเป็ตพร้อมคัดลอก

เครื่องยนต์ RPA

การทำงานอัตโนมัติแบบไม่ต้องเขียนโค้ด

Code Examples

Puppeteer + Chrome DevTools Protocol

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

การตั้งค่าพื้นฐาน
// 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');
ฟีเจอร์ขั้นสูง
// 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']
});
รูปแบบการทำงานอัตโนมัติ
// 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');

แนวทางปฏิบัติที่ดีที่สุด

หลีกเลี่ยงการตรวจจับ

  • ใช้ความล่าช้าที่สมจริงระหว่างการกระทำ (200-1000ms)
  • สุ่มการเคลื่อนไหวของเมาส์และตำแหน่งคลิก
  • เปลี่ยนขนาด viewport และ user agents
  • ล้างคุกกี้และที่เก็บข้อมูลระหว่างเซสชัน

ประสิทธิภาพ

  • ใช้อินสแตนซ์เบราว์เซอร์ซ้ำเมื่อเป็นไปได้
  • ใช้โหมด headless เพื่อประสิทธิภาพที่ดีขึ้น
  • บล็อกทรัพยากรที่ไม่จำเป็น
  • ใช้ connection pooling

การจัดการพร็อกซี่

  • หมุนเวียนพร็อกซี่ทุก 10-20 คำขอ
  • จับคู่ตำแหน่งพร็อกซี่กับเขตเวลา
  • ทดสอบคุณภาพพร็อกซี่ก่อนใช้งาน
  • ใช้พร็อกซี่ที่อยู่อาศัย/ISP สำหรับไซต์ที่ละเอียดอ่อน

การจัดการข้อผิดพลาด

  • ใช้ retry logic แบบ exponential backoff
  • ถ่ายภาพหน้าจอเมื่อเกิดข้อผิดพลาด
  • บันทึกการกระทำทั้งหมดสำหรับการดีบั๊ก
  • จัดการ CAPTCHA อย่างเหมาะสม

ตัวอย่างเครื่องยนต์ RPA

การทำงานอัตโนมัติการเข้าสู่ระบบ

ทำงานอัตโนมัติของกระบวนการเข้าสู่ระบบด้วยการสนับสนุน 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" }
  ]
}

การสกัดข้อมูล

สกัดข้อมูลจากหลายหน้า

// 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"] }
  ]
}

การส่งแบบฟอร์ม

ทำงานอัตโนมัติของการส่งแบบฟอร์มที่ซับซ้อน

// 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" }] }
  ]
}

ประกาศสำคัญ

เคารพข้อกำหนดในการให้บริการของเว็บไซต์เสมอเมื่อทำงานอัตโนมัติ ใช้การทำงานอัตโนมัติอย่างมีความรับผิดชอบและตรวจสอบให้แน่ใจว่าปฏิบัติตามกฎหมายและข้อบังคับท้องถิ่น

แหล่งข้อมูลเพิ่มเติม

พร้อมที่จะทำงานอัตโนมัติ?

รับใบอนุญาต Nox Core และเริ่มสร้างเวิร์กโฟลว์การทำงานอัตโนมัติที่ทรงพลังวันนี้

เริ่มต้น