主页 文献资料 教程 登录
受支持的任务类型
API 方法
文章
教程
GitHub
文献资料菜单

绕过反机器人屏幕

这种类型的任务,我们的工作人员在你选择的网页上导航,绕过任何反机器人屏幕,抓取cookies并将其返回到你的应用程序。然后,你可以使用这些cookie,用你最喜欢的编程语言在这个网站上自由导航。为了成功地绕过这种僵尸抓取页面,你还需要我们工人的浏览器的User-Agent值,并为我们提供一个质量好的代理。如果没有代理,这种方法将无法工作,因为所有的反僵尸解决方案都会将他们的cookies与访问者的IP地址和他们的用户代理相匹配。

反机器人屏幕示例

我们在最后一页抓住什么。

  • 饼干
  • 浏览器指纹
  • 从主窗口框架发出的最后一次HTTP请求的头信息

这项技术建立在我们的反关卡模板之上,只是我们自己管理模板并保持更新。使用这种类型的任务需要一个订阅,每个任务的费用是5个信用点。订阅价格从每月9.9美元起,包括5000个绕行任务。如果你不喜欢购买,你可以使用这个教程自己建立一个模板,继续从你的余额中支付,每个任务的成本约为0.002美元。

所有的过程都是由一个浏览器插件控制的,我们的工作人员在接受任务之前安装了这个插件。他们不做任何手动操作,基本上是自动打开一个新的标签,并启用你的代理,导航到你选择的页面,等待直到通过反僵尸屏幕,抓取数据,关闭标签,并通过API将数据传递给你的应用程序。

只接受高质量的代理,没有主机名,没有 "住宅代理",没有共享代理池。在美国/欧洲租一个VPS,用我们的说明安装一个SQUID服务器,总是可以的。在任务执行前,代理会被检查速度和兼容性。他们必须有低于1秒的快速响应时间,否则工人将取消你的任务。

检查一个网站是否支持反僵尸屏幕。

请注意,一些反僵尸屏幕正在使用先进的指纹技术,如SSL handshake fingerprinting,它可以识别哪种SSL/TLS客户端正在连接到网站。例如,Chrome浏览器有一个指纹,Firefox有一个,CURL有一个完全不同的指纹。不要把自己和用户代理混为一谈,它是一个较低层次的东西。在这种情况下,为了使用我们的服务,你需要使用相同的浏览器实例来重构我们工人的会话。由于我们的大多数工作人员使用的是 Chrome 浏览器,因此将 NodeJS+Puppeteer+Chromium 或 Selenium+Chromedriver 捆绑在一起就可以完成这项工作。例子包括。

任务对象

属性 类型 必须使用 用途
type 字符串 AntiBotCookieTask
websiteURL 字符串 我们的工作人员将从中进行浏览的目标网页的地址。
proxyAddress 字符串 ipv4/ipv6 代理服务器 IP 地址。禁止使用主机名或本地网络中的 IP 地址。
proxyPort 整数 代理服务器端口
proxyLogin 字符串 用于需要授权(基本授权)的代理服务器的登录名
proxyPassword 字符串 代理服务器密码

请求示例

CURL
          curl -i -H "Accept: application/json" \
     -H "Content-Type: application/json" \
     -X POST -d '{
    "clientKey":"YOUR_API_KEY_HERE",
    "task":
        {
            "type":"AntiBotCookieTask",
            "websiteURL":"https://somewebsite.com/",
            "proxyAddress":"8.8.8.8",
            "proxyPort":8080,
            "proxyLogin":"proxyLoginHere",
            "proxyPassword":"proxyPasswordHere"
        },
    "softId": 0
}' https://api.anti-captcha.com/createTask
        
PHP
          <?php

//git clone git@github.com:AdminAnticaptcha/anticaptcha-php.git

include("anticaptcha.php");
include("antibotcookie.php");

$api = new AntiBotCookie();
$api->setVerboseMode(true);

//your anti-captcha.com account key
$api->setKey("YOUR_API_KEY_HERE");

//target website address
$api->setWebsiteURL("https://somewebsite.com/");

//proxy access parameters
// DO NOT USE PURCHASED/RENTED PROXIES ON PROXY SERVICES!!!
// THEY WILL NOT WORK!
// USE ONLY PROXIES YOU INSTALL YOURSELF ON YOUR OWN SERVER OR FAST VPS
// USE PROPER PROXY SOFTWARE LIKE SQUID !
// INSTALLATION INSTRUCTIONS:
// https://anti-captcha.com/apidoc/articles/how-to-install-squid
$api->setProxyAddress("8.8.8.8");
$api->setProxyPort(1234);
//optional login and password
$api->setProxyLogin("login");
$api->setProxyPassword("password");

//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
$api->setSoftId(0);

//create task in API
if (!$api->createTask()) {
    $api->debout("API v2 send failed - ".$api->getErrorMessage(), "red");
    return false;
}

$taskId = $api->getTaskId();

//wait in a loop for max 300 seconds till task is solved
if (!$api->waitForResult(300)) {
    echo "could not solve captcha\n";
    echo $api->getErrorMessage()."\n";
} else {

    $result    =   $api->getTaskSolution();
    echo "\nTask result:\n";
    print_r($result);

    $assoc = json_decode(json_encode($api->getTaskSolution()), true);
    $userAgent = $assoc['fingerprint']['self.navigator.userAgent'];

    $cookies = [];
    foreach ($assoc["cookies"] as $name => $value) {
        $cookies[] = $name . "=" . $value;
    }
    $cookieStr = implode("; ", $cookies);

    echo "Use this User-Agent for your requests: $userAgent\n";
    echo "Use this cookies for your requests: $cookieStr\n";

    //example, may need to pass more headers with CURLOPT_HTTPHEADER:
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, "https://somewebsite.com/");
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
    //set worker's user-agent
    curl_setopt($ch,CURLOPT_USERAGENT, $userAgent);
    //set cookies
    curl_setopt($ch,CURLOPT_HTTPHEADER, array(
        'Cookie: ' . $cookieStr
    ));
    //set your proxies
    curl_setopt($ch,CURLOPT_PROXY, "8.8.8.8:1234");
    curl_setopt($ch, CURLOPT_PROXYUSERPWD, "login:password");
    //retrieve the content
    $content = curl_exec($ch);

}
        
Python
          #pip3 install anticaptchaofficial

from anticaptchaofficial.antibotcookietask import *
import requests

solver = antibotcookieTask()
solver.set_verbose(1)
solver.set_key("API_KEY_HERE")
solver.set_website_url("https://www.somewebsite.com/")
solver.set_proxy_address("1.2.3.4")
solver.set_proxy_port(3128)
solver.set_proxy_login("login")
solver.set_proxy_password("password")

# Specify softId to earn 10% commission with your app.
# Get your softId here: https://anti-captcha.com/clients/tools/devcenter
solver.set_soft_id(0)

result = solver.solve_and_return_solution()
if result == 0:
    print("could not solve task")
    exit()

print(result)

cookies, localStorage, fingerprint = result["cookies"], result["localStorage"], result["fingerprint"]

if len(cookies) == 0:
    print("empty cookies, try again")
    exit()

cookie_string = '; '.join([f'{key}={value}' for key, value in cookies.items()])
user_agent = fingerprint['self.navigator.userAgent']
print(f"use these cookies for requests: {cookie_string}")
print(f"use this user-agent for requests: {user_agent}")

s = requests.Session()
proxies = {
  "http": "http://login:password@1.2.3.4:3128",
  "https": "http://login:password@1.2.3.4:3128"
}
s.proxies = proxies

content = s.get("https://www.somewebsite.com/", headers={
    "Cookie": cookie_string,
    "User-Agent": user_agent
}).text
print(content)
        
NodeJS
          //npm install @antiadmin/anticaptchaofficial
//https://github.com/AdminAnticaptcha/anticaptcha-npm

const ac = require("@antiadmin/anticaptchaofficial");

//set API key
ac.setAPIKey('YOUR_API_KEY_HERE');

//Specify softId to earn 10% commission with your app.
//Get your softId here: https://anti-captcha.com/clients/tools/devcenter
ac.setSoftId(0);

(async () => {

    let solution = null;
    try {
        solution = await anticaptcha.solveAntiBotCookieTask(
            checkUrl,
            proxyAddress,
            proxyPort,
            proxyLogin,
            proxyPassword);
    } catch (e) {
        console.error("could not solve captcha: "+e.toString());
        return;
    }

    const fingerPrint = solution.fingerprint;
    const targetCookies = joinCookies(solution.cookies);
    console.log(`joined cookies: ${targetCookies}`);
    console.log(`user-agent: ${fingerPrint['self.navigator.userAgent']}`);

    try {
        let responseText = await axios.request({
            url: checkUrl,
            httpsAgent: agent,
            headers: {
                'User-Agent': fingerPrint['self.navigator.userAgent'],
                'Cookie': targetCookies,
                'Accept-Encoding': 'deflate',
                'Accept': 'text/html',
                'Accept-Language': 'en'
            }
        });
        console.log(responseText.data);
    } catch (e) {
        console.error('Could not request page')
        console.log(e.toString());
    }

})();


function joinCookies(object) {
    let resultArray = [];
    for (const key in object) {
        resultArray.push(key+"="+object[key])
    }
    return resultArray.join("; ");
}
        
      
NodeJS with Puppeteer
          /*

npm install @antiadmin/anticaptchaofficial puppeteer

* */

const anticaptcha = require("@antiadmin/anticaptchaofficial");
const pup = require('puppeteer');

//address behind cloudflare
const checkUrl = 'https://www.thewebsite.com/';
const domainName = 'www.thewebsite.com';


//Anti-captcha.com API key
const apiKey = 'API_KEY_HERE';

// STOP! IMPORTANT! Shared proxy services won't work!
// Use ONLY self-installed proxies on your own infrastructure! Instruction: https://anti-captcha.com/apidoc/articles/how-to-install-squid
// Again and again people people insist they have best purchased proxies. NO YOU DO NOT!
// Absolutely recommended to read this FAQ about proxies: https://anti-captcha.com/faq/510_questions_about_solving_recaptcha_with_proxy__applies_to_funcaptcha__geetest__hcaptcha_


const proxyAddress = '1.2.3.4';
const proxyPort = 1234;
const proxyLogin = 'mylogin';
const proxyPassword = 'mypass';


let browser = null;
let page = null;


(async () => {

    anticaptcha.setAPIKey(apiKey);
    const balance = await anticaptcha.getBalance();
    if (balance <= 0) {
        console.log('Topup your anti-captcha.com balance!');
        return;
    } else {
        console.log('API key balance is '+balance+', continuing');
        // anticaptcha.shutUp(); //uncomment for silent captcha recognition
    }

    let antigateResult = null;
    try {
        antigateResult = await anticaptcha.solveAntiBotCookieTask(
            checkUrl,
            proxyAddress,
            proxyPort,
            proxyLogin,
            proxyPassword);
    } catch (e) {
        console.error("could not solve captcha: "+e.toString());
        return;
    }

    const fingerPrint = antigateResult.fingerprint;

    try {
        console.log('opening browser ..');


        let options = {
            headless: true, //disable to see the browser window
            devtools: false, //enable to see developers console
            args: [
                '--window-size='+fingerPrint['self.screen.width']+','+fingerPrint['self.screen.height'],
                `--proxy-server=${proxyAddress}:${proxyPort}`
            ],

        };
        browser = await pup.launch(options);

        console.log('creating new page ..');
        page = await browser.newPage();
    } catch (e) {
        console.log("could not open browser: "+e);
        return false;
    }

    if (proxyPassword && proxyLogin) {
        console.log(`setting proxy authentication ${proxyLogin}:${proxyPassword}`);
        await page.authenticate({
            username: proxyLogin,
            password: proxyPassword,
        });
    }

    //screen size
    console.log('setting view port to '+fingerPrint['self.screen.width']+'x'+fingerPrint['self.screen.height']);
    await page.setViewport({width: fingerPrint['self.screen.width'], height: fingerPrint['self.screen.height']});

    //user agent
    let userAgent = '';
    if (fingerPrint['self.navigator.userAgent']) {
        userAgent = fingerPrint['self.navigator.userAgent'];
    } else {
        if (fingerPrint['self.navigator.appVersion'] && fingerPrint['self.navigator.appCodeName']) {
            userAgent = fingerPrint['self.navigator.appCodeName'] + '/' + fingerPrint['self.navigator.appVersion']
        }
    }
    console.log('setting browser user agent to '+userAgent);
    await page.setUserAgent(userAgent);

    console.log('setting cookies', antigateResult.cookies);
    let cookies = [];
    for (const name in antigateResult.cookies) {
        cookies.push({ name: name, value: antigateResult.cookies[name], domain: domainName })
    }
    await page.setCookie(...cookies);

    try {
        await page.goto(antigateResult.url, {
            waitUntil: "networkidle0"
        });
    } catch (e) {
        console.log('err while loading the page: '+e);
    }

    const htmlContent = await page.content();
    console.log("page content:\n\n", htmlContent);


})();


      

回应示例

JSON 没有错误
          {
    "errorId": 0,
    "taskId": 7654321
}
        
JSON 有错误
          {
    "errorId": 1,
    "errorCode": "ERROR_KEY_DOES_NOT_EXIST",
    "errorDescription": "Account authorization key not found in the system"
}
        

重获破解结果

用方法 getTaskResult 请求提供破解结果。首次提出请求之前,要给工作人员一些时间,例如 5 秒钟。如果工作人员还在忙,则过 3 秒再重试。

任务破解结果对象

属性 类型 用途
cookies 对象 来自反僵尸屏幕后面的页面的Cookies。把它们都连在一起,在你的HTTP请求中使用。
localStorage 对象 含有 localStorage 值的对象也在最后一页中获取,这类似于 Cookie。
fingerprint 对象 浏览器指纹参数。可一同使用这些参数与 Cookie 和 localStorage,以便在您的软件中重新创建工作人员浏览器会话。
在你的HTTP请求中使用self.navigator.userAgent值作为user-agent。
url 字符串 页面的 URL 是已完成的模板步骤的执行结果
lastRequestHeaders 数组 从浏览器的主窗口框架发送至网站的最后一个请求头。

回应示例

JSON 没有错误
          {
    "errorId": 0,
    "status": "ready",
    "solution": {
        "cookies": {
            "some_antibotcookie": "0A8VO9NX5N1s4LRoS4sJlFTCNzLj0dEfA_2whUh0E6ZjgQtM~I1cV7U2IhQx0~jnowNjg-Oi76b-MjYPd1GQAmIxh5-v~33PI8F",
            "maybe_another_id": "join_all_cookies_together"
        },
        "localStorage": {
            "some_value": "Might be used too in the future as a method to 'remember' visitors, so we collect it too.",
            "what_is_it": "localStorage is a more complex analogue of cookies, allowing to store larger objects in browser memory"
        },
        "fingerprint": {
            "self.navigator.userAgent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/101.0.0.0 Safari\/537.36",
            "self.screen.width": 1280,
            "self.screen.height": 768,
            "self.screen.availWidth": 1280,
            "self.screen.availHeight": 768,
            "self.screen.availLeft": 0,
            "self.screen.availTop": 25,
            "self.navigator.vendorSub": "",
            "self.navigator.productSub": "20030107",
            "self.navigator.vendor": "Google Inc.",
            "self.navigator.maxTouchPoints": 0,
            "self.navigator.hardwareConcurrency": 8,
            "self.navigator.cookieEnabled": true,
            "self.navigator.appCodeName": "Mozilla",
            "self.navigator.appName": "Netscape",
            "self.navigator.appVersion": "5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/101.0.0.0 Safari\/537.36",
            "self.navigator.platform": "MacIntel",
            "self.navigator.product": "Gecko",
            "self.navigator.language": "en-US",
            "self.navigator.onLine": true,
            "self.navigator.deviceMemory": 4
        },
        "url": "https://www.thewebsite.com/some/final/path/after_redirects",
        "lastRequestHeaders": [
            "sec-ch-device-memory: 8",
            "sec-ch-ua: \" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
            "sec-ch-ua-mobile: ?0",
            "sec-ch-ua-arch: \"x86\"",
            "sec-ch-ua-platform: \"macOS\"",
            "sec-ch-ua-model: \"\"",
            "sec-ch-ua-full-version-list: \" Not A;Brand\";v=\"99.0.0.0\", \"Chromium\";v=\"101.0.5005.115\", \"Google Chrome\";v=\"101.0.5005.115\"",
            "Upgrade-Insecure-Requests: 1",
            "User-Agent: Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/101.0.0.0 Safari\/537.36",
            "Accept: text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/avif,image\/webp,image\/apng,*\/*;q=0.8,application\/signed-exchange;v=b3;q=0.9",
            "Sec-Fetch-Site: same-origin",
            "Sec-Fetch-Mode: navigate",
            "Sec-Fetch-Dest: document",
            "Referer: https:\/\/somewebsite.com\/",
            "Accept-Encoding: gzip, deflate, br",
            "Accept-Language: en-US,en;q=0.9",
            "Cookie: some_antibotcookie=0A8VO9NX5N1s4LRoS4sJlFTCNzLj0dEfA_2whUh0E6ZjgQtM~I1cV7U2IhQx0~jnowNjg-Oi76b-MjYPd1GQAmIxh5-v~33PI8F"
        ]
    },
    "cost": "0.00858",
    "ip": "5.25.11.114",
    "createTime": 1637841143,
    "endTime": 1637841189,
    "solveCount": 0
}