WORKFLOW SNAPSHOT
- Extract a small page set with explicit selectors and a validation schema before scheduling a broader crawl.
- Suggested starting behavior: Timed session
- Validate the real application and destination
A practical Web scraping workflow
Extract a small page set with explicit selectors and a validation schema before scheduling a broader crawl.
- Prefer an approved API or feed when it provides the required fields.
- Keep related page sequences within a coherent session.
- Cache repeated content and back off on target errors.
How should a web scraper keep pagination and session state coherent?
Choose a session window that covers the related navigation or pagination sequence. Rotate between independent jobs where appropriate. If a page depends on cookies or continuation state, an exit change during that sequence can complicate the comparison.
Which selectors, required fields and retry outcomes matter before scale?
A 200 response can contain the wrong page, and rotation cannot repair a selector broken by a layout change.
Check document identity, required fields, and duplicate records before counting a fetch as successful.
Verify the Web scraping connection boundary
Check status, document identity, required selectors, encoding and schema before accepting a record. Detect verification pages and rate-limit responses explicitly instead of parsing their HTML as empty successful data.
Validate the source document before running selectors
Fetches a single source page and saves its response so document classification can precede selector-based extraction.
- 01Generate your endpoint
Choose HTTP / HTTPS and Sticky session for the complete workflow in Configure proxies.
- 02Set your proxy URL
Set
PS_PROXY_URLtohttp://USERNAME:PASSWORD@HOST:PORTusing your generated endpoint. For IP authentication, whitelist your machine and usehttp://HOST:PORT. Percent-encode special characters in credentials; these are proxy credentials, separate from your account password or API key. - 03Choose the destination
Set
Example URL · replace placeholders with your targetPS_TARGET_URLbefore running the code. Use one permitted public page from your scraping sample, chosen because its source is expected to contain the required fields; preserve its item or pagination identifier.https://example.com/catalog/items/sample-itemSet PS_EXPECT_TEXT to an item identifier or required source field that distinguishes the intended document. This optional check inspects the returned text without running JavaScript.
Python 3.10+ · python -m pip install requests · python ps_web_scraping.py# Fetches a single source page and saves its response so document classification can precede selector-based extraction.
# Use one permitted public page from your scraping sample, chosen because its source is expected to contain the required fields; preserve its item or pagination identifier.
import hashlib
import json
import os
import time
from pathlib import Path
from urllib.parse import urlsplit
import requests
class InspectSession(requests.Session):
# Leave redirect bodies streamed instead of preparing the next request.
def resolve_redirects(self, *args, **kwargs):
return iter(())
proxy = os.environ["PS_PROXY_URL"] # HTTP endpoint from ProxySight
target = os.environ["PS_TARGET_URL"] # https://example.com/catalog/items/sample-item
if urlsplit(proxy).scheme != "http":
raise ValueError("Use your generated HTTP proxy endpoint for this example.")
if urlsplit(target).scheme not in ("http", "https"):
raise ValueError("PS_TARGET_URL must be an HTTP or HTTPS URL.")
with InspectSession() as client:
client.trust_env = False # No ambient proxy, NO_PROXY or netrc overrides
started = time.monotonic()
with client.get(
target,
proxies={"http": proxy, "https": proxy},
headers={"Accept-Language": "en-US,en;q=0.9"},
timeout=(10, 20), allow_redirects=False, stream=True,
) as response:
body = bytearray()
for chunk in response.iter_content(16384):
body.extend(chunk)
if len(body) > 1048576:
raise RuntimeError("Response exceeds this example's 1 MiB limit.")
Path("scraping-source-document.html").write_bytes(body)
print(json.dumps({
"workflow": "web-scraping", "status": response.status_code,
"elapsed_ms": round((time.monotonic() - started) * 1000),
"bytes": len(body), "sha256": hashlib.sha256(body).hexdigest(),
"headers": {name: response.headers.get(name) for name in ['Content-Type', 'Content-Language', 'Location']},
}, indent=2))
expected = os.getenv("PS_EXPECT_TEXT", "")
if expected:
text = body.decode(response.encoding or "utf-8", errors="replace")
print("Expected text:", "found" if expected in text else "absent")
# A 200 status alone does not prove the intended page was returned.
# Inspect redirects, login prompts, 403 and 429 before another request.
Check status, content type and a known item marker before trusting successful selectors. A 200 response can contain a challenge or login form, and this GET does not render JavaScript; compare your extracted records with the saved source and keep missing-field outcomes explicit.
Response bodies are limited to 1 MiB for a small diagnostic. TLS verification stays enabled; redirects are left for you to inspect. Connection guide
Example: separate document identity from selector success
Build a reviewed fixture set containing a normal page, a redirect, an unavailable item, and a document missing optional fields. Give the parser an explicit way to classify each before extracting business data.
Keep source URL, parser version, and collection time with every record. This lets you distinguish a site change from a regression introduced by your own code.
{
"source_url": "PERMITTED_PUBLIC_URL",
"document_class": "RECORD_CLASS",
"parser_version": "YOUR_VERSION",
"required_fields": "RECORD_VALIDATION"
}Web scraping verification checklist
For this Web scraping workflow, record document class, extraction and provenance alongside the actual result. Use the evidence below to decide whether another observation is comparable before increasing the workload.
| Checkpoint | Hold constant or record | Expected evidence |
|---|---|---|
| Document class | Expected page type | Correct parser branch |
| Extraction | Required fields and formats | Complete valid output |
| Provenance | Source, time, parser version | Reproducible record |
Troubleshoot Web scraping results and connection errors
| Symptom | Check next | What the result tells you |
|---|---|---|
| 200 but no fields | Inspect document class | A challenge or wrong page may have arrived |
| Fields suddenly missing | Compare fixtures and parser version | Potential extraction regression |
| Repeated identical records | Check stable keys and URL deduplication | Not additional useful data |
Validate extracted records against the pages that produced them
Run a small permitted page set through fetch, parse, normalize and validate. Preserve source URLs and rejection reasons. Compare accepted fields with the original documents, then increase volume only after retries and concurrency remain within the stated request budget.
A LITTLE CLARITY
Common questions.
Is an HTTP success code enough for scraping validation?
No. Validate the actual page type and extracted fields.
What belongs in a scraping fixture set?
Normal, unavailable, redirected, and partially populated documents that exercise the parser’s real branches.
Which selectors, required fields and retry outcomes matter before scale?
Check status, document identity, required selectors, encoding and schema before accepting a record. Detect verification pages and rate-limit responses explicitly instead of parsing their HTML as empty successful data.