Prompt
How do I scrape websites that require login sessions?
Latest observation
If you have permission to access the site, the usual way to scrape pages behind a login is to reuse an authenticated session rather than trying to bypass anything.
Common approach
-
Log in normally
- Use a browser or an HTTP client to submit the login form.
- The site will usually respond with cookies, a session token, or both.
-
Preserve the session
- Keep the cookies/session headers from the login response.
- Reuse them for subsequent requests to protected pages.
-
Handle anti-bot measures carefully
- Some sites use CSRF tokens, redirects, MFA, CAPTCHA, or JS challenges.
- Only automate this if the site allows it and your access method complies with their terms.
Typical tools
Python requests
Good for simple login flows:
import requests
session = requests.Session()
# Step 1: load login page if you need CSRF tokens
login_page = session.get("https://example.com/login")
# Step 2: submit credentials (and CSRF token if required)
payload = {
"username": "your_user",
"password": "your_password",
}
resp = session.post("https://example.com/login", data=payload)
# Step 3: access protected content with the same session
page = session.get("https://example.com/account")
print(page.text)
If the site uses a CSRF token, you often need to parse it from the login page and include it in the POST.
Browser automation with Playwright or Selenium
Use this when:
- the site relies heavily on JavaScript,
- login requires MFA or complex flows,
- cookies are set after frontend scripts run.
Example idea with Playwright:
- open login page
- fill form
- submit
- save authenticated storage/cookies
- reuse them later
Important tips
- Inspect network requests in browser dev tools to see what the login flow actually sends.
- Watch for redirects after login; a successful login may redirect to a dashboard.
- Save cookies securely and don’t hardcode credentials.
- Respect rate limits and site policies.
- Do not try to defeat CAPTCHAs or access controls unless you’re explicitly authorized.
Best practice
If the site offers:
- an API,
- an export function,
- or official access tokens,
use that instead of scraping HTML.
If you want, I can show you:
- a
requestsexample with CSRF handling, or - a Playwright example for a login-required site.
Observation history
Unlock observation history
Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.
How did Obsurfable measure this prompt?
Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.
Which AI systems does Obsurfable collect answers from?
OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.