User Agents for Web Scraping: What They Are and Why They Matter
TL;DR
A user agent identifies the software making an HTTP request; it does not grant permission or execute JavaScript.
Python Requests can set User-Agent through a session's headers, which makes repeatable configuration easier than changing each call.
Use a descriptive crawler identity for an authorized collector, and verify the header at a server you control.
Changing a user-agent string does not make an HTTP client equivalent to a browser or resolve every 403 response.
Browser rendering, authentication, request limits, and content validation must be diagnosed separately.
Nstdata Crawl supplies managed page collection and LLM-ready outputs when running the retrieval layer yourself becomes the larger task.
What are user agents for web scraping?
User agents for web scraping are the User-Agent header values that identify the requesting client to a web server.
An HTTP library, browser, search crawler, and internal monitoring job can each send a different identity. A server may use that information for compatibility handling, logging, or policy decisions. The header is only one part of a request, and a server is not required to accept a request because the string resembles a browser.
The MDN User-Agent reference explains the header's purpose and the limitations of depending on it for browser detection. For an authorized collector, a clear identity and an appropriate request policy are more useful than an undocumented list of copied browser strings.
When collection also requires rendering and cleaned outputs, Nstdata Crawl addresses a broader problem than header configuration. This tutorial first shows how to inspect your own requests so you can tell the two problems apart.
Why does the same URL behave differently across clients?
The same URL can behave differently because the complete request and execution environment differ, including cookies, redirects, headers, network location, and JavaScript execution.
A site may serve different markup to different clients. Your parser might work against desktop HTML and fail against a simplified or mobile representation. Keep the request configuration stable during debugging, and save a small permitted response sample that demonstrates the difference.
Avoid assuming that the label βmobileβ alone explains a change. Browser viewport, account settings, language preferences, and client-side code can also influence the page. Record the actual response and final URL rather than reconstructing them from what a browser displayed earlier.
A browser performs work an HTTP library does not
Requests downloads an HTTP response. It does not execute the page's JavaScript or wait for a product grid to appear. A successful response containing a loading shell is an extraction failure if the product data is absent.
The API versus Playwright comparison helps decide whether your workflow needs a browser. Select that architecture based on the content requirement before spending time adjusting a header.
What do you need before testing a user agent?
You need Python, Requests, a terminal, and a local or authorized server that shows the header it actually received.
Item
Purpose
Value in this tutorial
Python environment
Runs the server and client
A project virtual environment
HTTP client
Sends requests
requests
Destination
Receives one test request
http://127.0.0.1:8765/
Header field
Identifies the collector
User-Agent
Example identity
Describes the test application
ResearchCollector/1.0
Timeout
Bounds the client wait
Connect and read timeouts in seconds
The local destination avoids sending test requests to an unrelated production website. Its sample collector identity is fictional; replace it with your team's approved name when deploying. Do not copy an organization or browser identity that misrepresents your application.
If your company requires a contact URL, use a working URL that your team controls. Keep personal email addresses and private account identifiers out of public headers.
How do you set and verify a user agent in Python?
Set the user agent in requests.Session().headers, then compare the server's received value with the value you intended to send.
Method 1: Verify a single request locally
Step 1: Install Requests
Run this in your project environment:
python -m pip install requests
Step 2: Start a local header receiver
Save the following as header_server.py and run python header_server.py in one terminal. The server returns only the header needed for this test, which avoids accidentally displaying cookies or authorization values.
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
classHeaderHandler(BaseHTTPRequestHandler):defdo_GET(self): body = json.dumps({"user_agent": self.headers.get("User-Agent")}).encode("utf-8") self.send_response(200) self.send_header("Content-Type","application/json") self.send_header("Content-Length",str(len(body))) self.end_headers() self.wfile.write(body)HTTPServer(("127.0.0.1",8765), HeaderHandler).serve_forever()
Step 3: Send the configured request
Run this client in a second terminal:
import requests
identity ="ResearchCollector/1.0"with requests.Session()as session: session.headers.update({"User-Agent": identity}) response = session.get("http://127.0.0.1:8765/", timeout=(3,10)) response.raise_for_status() received = response.json()["user_agent"]assert received == identity,"Unexpected outgoing user agent"print({"received_user_agent": received})
The executed local test returned ResearchCollector/1.0. That result establishes that the receiver saw the configured header. It says nothing about permission, target-site access, or browser compatibility.
Method 2: Reuse a stable identity in a collection job
Step 1: Define one session configuration
Move the session initialization into the module that owns outbound requests. Keep the identity constant during a run so that response differences can be investigated against a known configuration. The Requests quick start documents custom headers, response status checks, and timeouts.
Step 2: Apply the site's collection policy
Check applicable terms and crawler rules before scheduling the job. The Robots Exclusion Protocol defines robots.txt behavior; robots.txt is not an authorization mechanism or a substitute for permission.
Step 3: Inspect a bounded response sample
Verify the final URL, status, content type, and expected business fields. Avoid logging complete headers or bodies when they may contain secrets or personal data. A small content fingerprint and an approved diagnostic sample are often sufficient.
This stable configuration makes a change reviewable. If a job suddenly returns an empty table, you can compare the current response with a known-good sample instead of wondering whether header rotation changed the page variant.
When should you use Nstdata Crawl instead of managing retrieval?
Use Nstdata Crawl when page access, rendering, and output preparation require more infrastructure than the header configuration itself.
Nstdata Crawl is a Web Crawling API for LLM-ready data. A collector can submit public pages and receive formats suited to downstream parsing or AI use. Standard managed calls use built-in access infrastructure without requiring a separately configured proxy username, password, host, and port. Rendering controls help address content that appears after browser execution. Your application still needs permission checks, expected-field validation, and a clear failure policy.
What does the product add to this workflow?
Multiple outputs: Markdown supports text processing; HTML supports DOM parsing; links support discovery; screenshots and PDFs support review; raw data supports debugging. Structured business JSON is a separate schema task.
Bounded site collection: Page limits, depth limits, and URL filters help prevent a narrow monitoring job from becoming an uncontrolled crawl.
Task diagnostics: Task IDs and failure fields distinguish submission, processing, completion, and failure.
Managed access: Built-in proxy routing removes an additional configuration step for a standard Crawl request. It does not establish collection permission or guarantee access to a target.
Add https://mcp.nstdata.io/crawl in an MCP client that supports Streamable HTTP, then authorize. The Nstdata Crawl MCP guide covers the tool workflow.
Step 2: Request one authorized page
Use a known public test page rather than a large target list:
Read https://quotes.toscrape.com/ with Nstdata Crawl as Markdown.
Submit one scrape only. Read a returned markdownRef before inspecting it.
Check that quote authors are present. Report any task error as an error.
Do not change request identity or retry the submission automatically.
Step 3: Accept content only after inspection
Check the completed task and the returned body. If the response is a reference, retrieve it. A separate test against a public header endpoint returned internal_error; that is a failed task, not evidence that a user agent was accepted or rejected. The correct response is to investigate the failure rather than invent a successful header observation.
For this article's header verification, the local receiver above provides the direct evidence. Use the current Crawl pricing information when evaluating the managed collection cost.
Why is a scraper still failing after changing its user agent?
A scraper can still fail because the problem is unrelated to the user-agent string, or because several request conditions must be satisfied together.
Symptom
Plausible cause
Next action
403 response
Access policy or missing authorized context
Check permission and approved authentication flow
429 response
Request rate exceeds an allowed limit
Respect retry guidance and reduce the request rate
HTTP 200 with no records
Loading shell or changed markup
Inspect HTML, then use rendering if required
Different language or currency
Regional or account context
Hold location, cookies, and locale settings constant
JSON parsing error
HTML error page or unexpected response
Check content type and a redacted body sample
Timeout
Slow connection, rendering, or downstream work
Identify the stage and bound its wait
Use the common scraping errors guide to classify failures before retrying. Repeating a denied request with a different identity can obscure the real cause and increase unnecessary traffic.
How should you maintain request identities over time?
Maintain request identities as part of an approved, documented collection configuration with versioned changes and observable results.
Start with one stable identity, one permitted destination, and one expected-content assertion. Retest when the client implementation changes, and avoid treating copied browser strings as a maintenance strategy. If you operate several independent collection jobs, Nstdata Proxy Manager is a separate capability to evaluate for centralized proxy routing and operations.
The best user agent depends on the site's expectations and your authorized workflow. A descriptive, stable identity is useful for a collector you operate; no string guarantees access.
Q: Does setting a Chrome user agent make Requests a browser?
Setting a Chrome user agent does not give Requests a browser engine, JavaScript execution, or browser state. Use browser execution when the data requires it.
Q: Should every request use a different user agent?
Every request does not need a different user agent. Stable configuration makes authorized collection and debugging easier; change identities only for a documented requirement.
Q: Can a user agent bypass authentication?
A user agent cannot provide valid authentication or permission. Use the site's approved access method and stop when the workflow is not authorized.
Q: How do you prove which header was sent?
Prove the sent header by inspecting it at a server you control or an authorized diagnostic endpoint. A local receiver is sufficient for verifying your client configuration without exposing other headers.
Lena Zhou
Nov. 26th 2026
Experience Nstproxy Crawl - Start Your Free Trial Today
Crawl entire websites with a single API request
Turn any website into Markdown, HTML, JSON, links, PDFs and more β without managing crawling infrastructure.