DEV Community

Fabian
Fabian

Posted on

Scraper input from strangers: country names, 01.08.2026, and why I stopped throwing

When you run your own scraper you type the input the way your code expects it. When strangers run it from a public listing, they type Germany into a field you documented as an ISO country code, 01.08.2026 into a date field, and "50 ads" into a number field. On the Apify Store a failed run also counts against your public success rate, which the Store uses for ranking. So I moved most input handling into one small module whose rule is: understand what the user meant, log a warning, and keep going.

Below is what's in it and the run that made me write it.

The run that started it

My LinkedIn Ad Library actor took a start date and a country. A user sent 01.08.2026 as the date. I passed it straight to LinkedIn, LinkedIn answered with HTTP 500, and the run failed. While fixing that I found a second problem in the same code: I sent the country as countryCode=DE, which LinkedIn silently ignores. The parameter it actually reads is countries=DE. For one advertiser that was the difference between 629 ads (Germany) and 9,530 (everywhere). Nobody had complained, because a list of ads from all countries looks like a valid result.

Dates

The parser takes YYYY-MM-DD, YYYY/MM/DD, DD.MM.YYYY, slash dates, Unix timestamps and anything Date.parse understands, and returns YYYY-MM-DD or null:

let m = str.match(/^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})/);
let out = m ? iso(m[1], m[2], m[3]) : null;
// DD.MM.YYYY is always European order
if (!out && (m = str.match(/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/))) out = iso(m[3], m[2], m[1]);
⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026 ⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026

iso() builds the string and checks it round-trips through Date, so 31.02.2026 comes back as null instead of March 3rd.

Slash dates are the hard part. 31/12/2026 can only be day first, 12/31/2026 can only be month first, and a part above 12 decides. 08/01/2026 could be either. My first version read those as day first, quietly, which changed the result for every US user who had been sending that format. The current version keeps the US reading for ambiguous dates and says so in the log:

Ambiguous startDate "08/01/2026" - reading it as MM/DD/YYYY (2026-08-01). Use YYYY-MM-DD to be sure.
⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026 ⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026

Something that can't be parsed at all logs a warning and the filter is dropped. The run continues without it.

Countries

Hardcoding a country list felt wrong, and it turns out Node already has one. Intl.DisplayNames gives the English name for every region code, so I build a name-to-code map at startup:

const names = new Intl.DisplayNames(['en'], { type: 'region' });
for (let a = 65; a <= 90; a++) for (let b = 65; b <= 90; b++) {
    const code = String.fromCharCode(a, b);
    const name = names.of(code);
    if (!name || name === code || name === 'Unknown Region' || RETIRED.has(code)) continue;
    map[name.toLowerCase()] = code;
}
⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026 ⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026

Two things to watch: ICU also names retired codes (UK, SU, YU and others), so those get skipped, and a few common inputs need aliases on top (uk, usa, deutschland, españa, türkiye, holland). Values like worldwide, all or any mean no filter. Anything unknown is a warning and no filter, not an exception.

Numbers and lists

Numbers come in as 50, "50", "1,000" or "50 ads". Strip spaces, commas and underscores, take the leading number, fall back to the default with a warning if there isn't one.

Lists come in as arrays, newline-separated strings, semicolon-separated strings, or arrays of { url } objects from the Apify request-list editor. One function flattens all of that into unique trimmed strings. It also accepts a few field names that aren't in the schema (someone sends urls instead of startUrls) and logs which one it used.

Where I do fail

Being tolerant inside the run doesn't mean starting runs that can't work. Two places where failing is still the right answer:

Empty input, before the run exists. The platform validates input against the schema before it starts anything. A required field with a prefill and minItems: 1 but no default makes an empty start return HTTP 400, and no run is created. If you add "default": [] next to required, that check never fires, the container starts, and you get a failed run in your stats. The prefill is what people see in the form, so they can still click Start and get a working run.

Nothing usable after parsing. If every entry was invalid, the run exits with code 1 and a status message that says what was wrong. On Apify that message is the only thing the user sees, and I don't see their run at all. In SDK 3.7.2, Actor.exit({ exitCode: 1, statusMessage }) sends the message and exits about 1 ms later without waiting, and on roughly 1 in 5 of my failed runs the message never arrived. Setting it first fixes that:

export async function fail(msg) {
    await Actor.setStatusMessage(msg, { isStatusMessageTerminal: true, level: 'ERROR' }).catch(() => {});
    await Actor.exit({ exitCode: 1, statusMessage: msg });
}
⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026 ⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026

The whole module is about 400 lines and the only dependency is apify. Most of it is the parsing above. It's shared by every actor I publish, so a fix lands everywhere with one deploy.

The LinkedIn actor from the story above is here if you want to throw odd input at it: https://apify.com/pulsedata/linkedin-ad-library-scraper

Top comments (1)

⚽ Live Match: fade/scraper input from strangers country names and why i stopped throwing b - Info Live Streaming 2026
 
userxnom profile image
Abdullah Naseer •

The 629 vs 9,530 ads story is the one that sticks with me, because it's worse than a crash — it's a plausible wrong answer. A failed run at least tells you something went wrong; a silently ignored countryCode=DE hands you a bigger list that looks perfectly valid, and nobody complains because more results feel like better results. That asymmetry is exactly why "log a warning and keep going" is the right default for input parsing but the wrong instinct for the API call itself.

Two details I really liked: refusing to silently guess on ambiguous dates like 08/01/2026 and logging the assumption instead, and the schema trap — a "default": [] next to required quietly disabling the platform's own empty-input check, so a run starts just to fail in your public stats. That's the kind of platform quirk you only learn by watching your success rate drop for a reason that isn't your code.

The exit-code race is a nice catch too — 1 in 5 failed runs losing their status message means your most important debugging signal is the one that disappears when you need it most.

Which ambiguous input still worries you most — the ones you now warn on, or the ones you suspect are still passing through unnoticed? And have you considered surfacing a short "what I guessed" summary at the top of the run log, so a user can spot a wrong assumption without reading every warning line?