Tự động hóa
Puppeteer và Playwright, thẳng vào hồ sơ của bạn
Mỗi hồ sơ đang mở đều có địa chỉ gỡ lỗi riêng. Hãy nối mã của bạn đúng vào hồ sơ đó: với dấu vân tay, cookie và proxy của chính nó. Có trong mọi gói, kể cả gói miễn phí.
- 1Bật giao diện cục bộ trong ứng dụng: cài đặt, mục «API cục bộ». Sao chép khóa.
- 2Yêu cầu mở một hồ sơ. Câu trả lời là một địa chỉ chỉ thuộc về hồ sơ đó.
- 3Nối mã của bạn tới địa chỉ ấy như tới một trình duyệt bình thường.
- 4Làm việc như thường lệ. Dấu vân tay, cookie và proxy đã sẵn sàng.
JavaScript (puppeteer-core)
const puppeteer = require('puppeteer-core');
(async () => {
// 1. Ask the app for this profile's debugging endpoint.
const started = await fetch(
'http://127.0.0.1:50325/api/v1/browser/start?profileId=YOUR_PROFILE_ID',
{ method: 'POST', headers: { 'x-api-token': 'YOUR_API_TOKEN' } },
).then((r) => r.json());
// 2. Attach to it like to any other browser.
const browser = await puppeteer.connect({
browserWSEndpoint: started.data.ws,
defaultViewport: null,
});
const [page] = await browser.pages();
await page.goto('https://example.com');
})();
Python (Playwright)
import requests
from playwright.sync_api import sync_playwright
# 1. Ask the app for this profile's debugging endpoint.
started = requests.post(
"http://127.0.0.1:50325/api/v1/browser/start",
params={"profileId": "YOUR_PROFILE_ID"},
headers={"x-api-token": "YOUR_API_TOKEN"},
).json()
# 2. Attach to it like to any other browser.
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(started["data"]["ws"])
page = browser.contexts[0].pages[0]
page.goto("https://example.com")
Một điều cần biết trước khi kết nối
Puppeteer and Playwright turn on Runtime.enable and Page.enable the moment they attach. Runtime.enable puts observers inside Chromium that page scripts can notice. Our own automation builder never turns it on. It turns on Page.enable only while a flow runs, on the tabs the flow uses, so it can answer a page's alert or confirm; a test page that looks for traces saw nothing from it on either engine. If the site you work with checks for this, build the sequence in the app instead.
Hoặc làm hoàn toàn không cần mã
Mười sáu loại bước trong một cửa sổ: mở, nhấp, gõ, chờ, đọc, rẽ nhánh. Không có bộ quan sát nào bị phát hiện, và không phải cài gì cả.
Xem ứng dụng làm được gì