跳到主要内容

自动化

Puppeteer 与 Playwright,直接连到你的配置文件

每个打开的配置文件都有自己的调试地址。把你的代码连到那个配置文件上:它的指纹、它的 Cookie、它的代理都在。所有套餐都包含,免费套餐也一样。

  1. 1在程序里打开本地接口:设置中的「本地 API」,复制密钥。
  2. 2请求打开一个配置文件。返回的地址只属于这个配置文件。
  3. 3像连接普通浏览器一样,把你的代码连到这个地址。
  4. 4照常工作。指纹、Cookie 和代理都已经就位。

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")

连接之前需要知道的一件事

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.

或者完全不用写代码

窗口里有十六种步骤:打开、点击、输入、等待、读取、分支。没有可被察觉的观察器,也不用安装任何东西。

看看程序能做什么