WORKFLOW SNAPSHOT
- Collect a small dataset whose fields, freshness, and duplicate rules are defined before fetching.
- Suggested starting behavior: Per-request rotation
- Validate the real application and destination
A practical Structured data collection workflow
Collect a small dataset whose fields, freshness, and duplicate rules are defined before fetching.
- Specify required fields and acceptable value formats.
- Cache unchanged documents and deduplicate source URLs.
- Keep route, parser version, and fetch time in the record.
When should a structured-data collector rotate between observations?
Use independent assignments for independent permitted records where useful. Keep pagination or a related source journey coherent when it depends on session state. Rotation controls routing; schema validation determines whether the returned data is usable.
Which data-schema and deduplication checks must pass before scale?
A completed HTTP request can contain an error page or incomplete data. Increasing rotation will not repair a parser or an undefined schema.
Test required-field completeness and compare a manual sample before scheduling a larger run.
Verify the Structured data collection connection boundary
Define required fields, units, freshness, null handling and duplicate keys before scheduling a larger job. A successful response containing a challenge page or empty required field should not enter the dataset as a valid record.
Validate a JSON source before the extraction pipeline
Fetches a bounded JSON source, checks that it decodes as JSON and saves the exact response for your record validator.
- 01Generate your endpoint
Choose HTTP / HTTPS and Every request for independent observations 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 an explicitly approved read-only JSON dataset URL or a fixture you control, with a small non-sensitive record sample and a documented schema.https://example.com/datasets/catalog-sample.jsonSet PS_EXPECT_TEXT to a required field name or stable sample-record key. This optional check inspects the returned text without running JavaScript.
Python 3.10+ · python -m pip install requests · python ps_data_scraping.py# Fetches a bounded JSON source, checks that it decodes as JSON and saves the exact response for your record validator.
# Use an explicitly approved read-only JSON dataset URL or a fixture you control, with a small non-sensitive record sample and a documented schema.
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/datasets/catalog-sample.json
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("structured-data-source.json").write_bytes(body)
print(json.dumps({
"workflow": "data-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', 'Retry-After', 'X-RateLimit-Remaining']},
}, 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.
Inspect the JSON root type, expected record marker, content type and cache metadata before passing the file to your schema checks. Parseable JSON alone does not prove required fields, freshness, deduplication or permitted reuse; validate these against the saved source.
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: validate structured records after extraction
Write the output schema before the fetch loop: stable identity, source, collection time, required fields, and allowed missing states. Separate fetching from parsing and validation so their failures remain understandable.
Use a reviewed fixture set with a normal record, an unavailable item, and a document missing optional fields. It should reveal a schema regression without requiring another live collection run.
{
"record_key": "STABLE_KEY",
"source_url": "RECORD_SOURCE",
"collected_at": "RECORD_TIMESTAMP",
"schema_version": "YOUR_SCHEMA",
"validation": "RECORD_RESULT"
}Structured data collection verification checklist
For this Structured data collection workflow, record identity, schema and freshness 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 |
|---|---|---|
| Identity | Stable record key and source | Deduplication is possible |
| Schema | Required fields and allowed formats | Valid records distinguished from partial output |
| Freshness | Collection timestamp | The observation has a known time |
Troubleshoot Structured data collection results and connection errors
| Symptom | Check next | What the result tells you |
|---|---|---|
| Requests succeed, data incomplete | Inspect parser and schema | Transport succeeded but extraction failed |
| Record count inflated | Check duplicate keys | Repeated pages may be counted twice |
| Missing values look plausible | Use explicit missing states | Avoid invented default data |
Validate a small collected dataset before increasing concurrency
Collect a small sample and run it through the intended normalizer and validator. Save source URL, retrieval time and a rejection reason for failures. Compare accepted records with the original documents before adding workers or broadening the source list.
A LITTLE CLARITY
Common questions.
What is the best success metric for data scraping?
Valid, fresh, deduplicated records are more useful than raw request counts.
Why keep parser and schema versions?
They let you distinguish source changes from changes introduced by your own extraction pipeline.
Which data-schema and deduplication checks must pass before scale?
Define required fields, units, freshness, null handling and duplicate keys before scheduling a larger job. A successful response containing a challenge page or empty required field should not enter the dataset as a valid record.