NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

Web scraping

How should scrapers handle login pages?

Log in as rarely as possible: authenticate once with an account you are entitled to use, save the session, and reuse it until the site asks you to sign in again.

The principle

A login is the most sensitive request a site receives, so it is also the most guarded. Sites watch it for rate, IP reputation and failed attempts, and many put a CAPTCHA on it. The less often your scraper logs in, the fewer of those checks it meets. Authenticate once, keep the cookies the site sets, and send them with every later request. Only log in again when a request shows that the session has ended.

Use only accounts that belong to you or that you are authorized to use, and only for data the account is allowed to see. Automating logins to other people's accounts is account takeover, which is never acceptable.

What a login form usually needs

  • A CSRF token. A hidden field such as csrf_token or authenticity_token, read from the login page in the same session and posted back.
  • The right field names. Copy them from the form, not from guesses: email, username, login[password] and so on.
  • Cookies from the page load. Many sites set a session cookie before login and expect it on the POST.
  • A CAPTCHA answer when the form has a widget, placed in the field or callback the page uses.

A compact Python flow

import re, requests

def sign_in(http, email, password, solve_v2):
    form_page = http.get("https://portal.example.com/sign-in", timeout=20).text
    csrf = re.search(r'name="authenticity_token" value="([^"]+)"', form_page).group(1)
    key = re.search(r'data-sitekey="([^"]+)"', form_page)
    fields = {"authenticity_token": csrf, "user[email]": email, "user[password]": password}
    if key:
        fields["g-recaptcha-response"] = solve_v2("https://portal.example.com/sign-in", key.group(1))
    done = http.post("https://portal.example.com/sign-in", data=fields, timeout=20)
    return "sign-out" in done.text

def still_signed_in(response):
    return "/sign-in" not in response.url and response.status_code != 401

Save http.cookies to disk after a successful login and load them at the start of the next run, so a daily job does not sign in every day.

Detecting an expired session

Sessions end for many reasons: a timeout, a password change, a server restart or a security rule. Typical signs are a redirect to the login URL, a 401 or 403 status, or a page that suddenly contains the login form. Check for these after each request, log in again once, and stop with an alert if the second login also fails, instead of retrying in a loop that would look like an attack.

CAPTCHAs and two-factor prompts

A widget on the login form is handled like any other: read the site key, solve, submit. A reCAPTCHA v2 checkbox solves under 9 seconds; a Turnstile widget takes a Cloudflare Turnstile task. Two-factor prompts are different: they exist to involve a person or a device. For accounts you own, the cleanest route is often an app password or API token the site offers for automation. If neither exists, keep the session alive as long as possible so the prompt appears rarely, and enter the code manually when it does.

Browser or HTTP client?

If the login is a plain HTML form, an HTTP client is faster and easier to run on a schedule. If the form is built by JavaScript, posts through an API with signed values, or runs a fingerprint script first, log in with Playwright or Puppeteer, then export the cookies to your HTTP client. The page on managing cookies and sessions shows how to move them between tools, and why automation fails on login pages lists the usual traps.

Pacing and politeness

Run logged-in scrapers at a gentle pace. An authenticated session is tied to one identity, so a burst of requests is easy to attribute and easy to suspend. Spread work out, avoid parallel sessions on one account unless the site allows them, and read the terms of service, which often say what automated access is permitted.

Common questions

How often should a scraper log in?

Only when the saved session stops working. Reusing cookies is faster and attracts fewer checks.

Where do I find the CSRF token?

In a hidden input of the login form or a meta tag in the page head, read in the same session that posts the form.

Can I solve the login CAPTCHA with a plain HTTP client?

Yes. Token widgets such as reCAPTCHA and Turnstile return a string you post with the form fields.

What about accounts with two-factor authentication?

Prefer an app password or API token the site provides for automation; otherwise keep sessions long and enter codes by hand.

Is it fine to share one account across many workers?

Usually not. Parallel sessions on one account look suspicious and may break the site's terms.

Keep reading