Null is an answer: what a scraper should do when the page does not say
A scraped record is only useful if you can tell what was read from what was assumed. Three rules we hold our records to, and why each one matters downstream.
Data3 min read
By the EnrichedNow team
The easiest scraper to write always returns something. The salary field is empty? Put 0. No closing date? Add thirty days to the posting date. The page would not load? Return an empty list. Every one of those choices makes the output look complete, and every one plants a falsehood in somebody's database.
The person who pays for it is whoever uses the data next. An average salary dragged down by zeros. A dashboard of "expired" jobs that never had a closing date. A company marked "not hiring" because its site was down on Tuesday.
These are the three rules our records follow instead.
1. What the page does not say is null
If a product page shows no struck-through price, was_price is null. If a job posting gives no closing date, valid_through is null. The field is always present, so your code never has to ask whether a key exists. Its value tells you the truth: this was looked for and the page did not state it.
null is different from 0 and from an empty string, and the difference is the point. A rating of 0 is a claim about the product. A rating of null is a claim about the page.
2. Not being able to look is not finding nothing
Every run ends in one of five ways, and two of them carry records you can use:
| Status | Records | Charged | Means |
|---|---|---|---|
ok | Zero or more | Yes | The target was read. Zero records means there was nothing to find. |
partial | One or more | Yes | Records were found, but something stopped the run from reading everything. |
failed | None | No | The run could not read the target. |
unsupported | None | No | The target needs something we do not do. |
cancelled | Zero or more | No | You cancelled the run and it stopped. |
An ok run with zero records is a real, complete answer, and it is charged like any other. A failed run is not charged at all. We are paid when we read the page, which keeps our interest lined up with yours: a scraper that quietly returns nothing earns nothing.
A partial run says so, with a reason. It is never passed off as a complete one.
3. Say how the value was obtained
When a record can be reached by more than one road, the record says which was taken. A job opening carries extraction: ats when it came from the applicant tracking system behind the careers page, page when it was read off the page itself. A run's diagnostics.facts names what was read to produce it.
You may never look at those fields. They are there for the day a number looks wrong and you need to know whether to doubt the source or the reading.
What this asks of your code
- Store
nullas null. Do not let a database default or a dataframe turn it into zero. - Branch on the run's
statusbefore you touch its records. Keep "read, and empty" apart from "not read". - When a run is
partial, keep itsreasonbeside the records it produced.
The statuses and every reason are in Results and statuses; what is charged and when is in Usage and units.
Questions
- Why does a record have null fields?
- The page did not state that value. The field is kept, with null, so that a value we do not know is never confused with zero or an empty string.
- Am I charged for a run that fails?
- No. A run is charged only if it ended ok or partial.
- Is a run with zero records a failure?
- Not if it ended ok. That means the target was read and there was nothing to find, which is a complete answer.