Skip to content

Releases

v0.2.1

Choose a tag to compare

@jehrr jehrr released this 16 Oct 11:10
ffad07e

Behaviour change. A page that serves fewer than twelve ads while the
response's own total says more remain now makes the run incomplete:
stop_reason: short_page, status partial, exit 6 (was status
complete, exit 0). The ads it did serve are kept.

Behaviour change. --allow-empty now writes an empty file only for a
genuine empty result, and its sidecar says status: empty (was
failed). A blocked or failed run with --allow-empty no longer
replaces an earlier output with an empty file. It keeps its exit code
(3 or 5) and leaves that output and its sidecar untouched.

Fixed

  • --allow-empty could destroy the output it exists to protect. With
    the flag, a blocked run or a run that never obtained its content wrote
    an empty JSON and CSV over the previous good result, plus a sidecar
    saying failed. A genuinely empty, complete run (the library's own
    total: 0) was labelled failed too, so diff_runs.py refused it. Now:

    • A finished run whose answer was nothing writes [], a header-only
      CSV and a sidecar with status: empty and its stop_reason. It
      exits 4.
    • Blocked (3), never obtained (5) and partial (6) keep their exit codes.
      No empty row file is written for them, and an earlier output at the
      same --out is kept byte for byte, sidecar included.
    • When nothing earlier exists, a blocked or failed --allow-empty run
      writes only a sidecar, with status: blocked or failed.
    • diff_runs.py compares an empty run like a complete one.
  • A listing cut short was reported as a complete region. On
    2026-10-13 the library served France two ads on page 1, with
    has_more: false beside total: 17,071,905, and Germany eleven on
    page 2. The run stopped those regions as has_more_false and ended
    complete. The site's page size is twelve (45 of the 47 pages in the
    canary artifacts from 2026-10-09 to 2026-10-15 carried exactly twelve)
    and it documents no cap, so all three engines now record such a page
    under short_pages in the sidecar and stop that region as
    short_page. A short last page that brings the count up to the stated
    total is still the end of the listing, and the run is complete.

Changed

  • The canary's per-region floor follows the page contract, not a
    count.
    It required at least 12 ads per region. It now requires a full
    first page of twelve and at least one new ad on page 2 in every region,
    fails on any recorded short page, and re-checks every dumped payload
    for a short page the run did not record.
  • The canary no longer requires creative_type on every row. Some
    records carry no creative at all: on 2026-10-15, 4 of 71 had
    videos: [] and image_urls: [] in the payload itself, and the
    parser's null is the honest value for them. The canary now checks the
    column against the dumped record. It must be null exactly when the
    record carries neither a video nor an image.

v0.2.0

Choose a tag to compare

@jehrr jehrr released this 15 Oct 22:35
76e7412

Behaviour changes. A response whose own total or has_more says
ads exist but whose data is empty is now a failure, not "no ads": a run
holding nothing exits 5 (was 4), and a run with other rows exits 6.
Output files follow the umask (were always 0600) and an existing file
keeps its mode. CSV cells that would run as a spreadsheet formula get a
leading '. Negative --retries, --retry-delay, --delay and
--proxy-block-retries are refused as usage errors (exit 2).

Fixed

  • An empty data beside a non-zero total read as "no ads". The
    classifier returned no_ads for {"total": 5000, "has_more": true, "data": []}, so a run reported the query as matching nothing (exit 4)
    while the response stated 5,000 matches. It is now a parse error in the
    classifier, and each engine treats a zero-row page under such an envelope
    the same way. A genuine total: 0 is still exit 4.
  • Output files were 0600 whatever the umask. The atomic writer kept
    the temporary file's owner-only mode. A new file now gets
    0666 & ~umask and an existing one keeps its own mode, including the
    .meta.json sidecar.
  • CSV formula injection. Advertiser names, titles and creative URLs
    are advertiser-written text. String cells starting with =, +, -,
    @, tab, CR or LF are prefixed with ' in the CSV (after list joining);
    numbers and JSON are untouched. The sidecar records csv_cells_escaped,
    and a caller's own sidecar fields win a name collision.
  • Negative counts and delays. --retries -1 was silently read as 0
    and --retry-delay -1 crashed the first retry with exit 1. All three
    engines (and the refusal-only Scraper API client) now reject negative
    values with an argparse error naming the flag. --retries has help text
    saying it counts extra attempts; --retries 0 still fetches once.
  • Wording. The README said 25 columns per ad (there are 26), and
    comments described sibling routes as if they were this repo's.

Changed

  • Public files no longer cite an external instruction file or its section
    numbers; each comment states its rule directly. A suite check keeps it
    that way. tiktok_payload.py changed only in comments, and its recorded
    digest was updated.
  • The canary keeps the exact payloads it received (--dump-html) in its
    artifact, so a red run can be diagnosed.

v0.1.2

Choose a tag to compare

@jehrr jehrr released this 29 Sep 23:40
48f1704

Behaviour changes. --query now filters: it was sent without the
search type the library needs and was ignored, so every keyword run
returned the whole region. A keyword that matches nothing is exit 4 (the
library's own total: 0), not exit 5. diff_runs.py refuses two runs
that asked a different keyword, region set, ad type or window.

Fixed

  • A recovered page is not a blocked one. _fetch_with_policy kept a
    "refusal seen" flag that a later successful attempt never cleared, so a
    retry that got the page still reported it blocked. Measured live on
    2026-09-29 (pyppeteer, @nasa): one empty HTTP 200, then the profile,
    then partial / stop_reason: blocked with pages_failed: []. And the
    HTTP -> browser switch spent a --retries attempt, so with --retries 0
    a browser started and was never asked for the page. Both fixed in all
    three engines, with a check that drives the real function.
  • --query was ignored. search_body() sent query_type: ""; the
    library's UI sends "1", and only then does the keyword filter.
    Measured 2026-09-29, DE, same window: 19,000,309 / 19,000,308 (keyword /
    nonsense) before, 416 / 0 after, in all three engines. The canary now
    runs a positive and a negative keyword control.
  • "Nothing matched" read as an API error. The library's answer is
    {"code": 0, "total": 0, "has_more": false} with no data key, and the
    classifier called that an error, so the fixed keyword search would have
    made every empty result exit 5. It is exit 4.
  • The envelope is judged before any row. A non-zero code is the API
    refusing even when data is [] (it read as "no ads"); data that is
    not a list is a parse error; records none of which carries an id
    raise instead of reading as an empty region.
  • A failed region was listed as having no ads. failed holds region
    numbers and was compared against a region name.
  • diff_runs.py compares only runs that asked the same question. The
    sidecar now records query, query_type, ad_type and window_days.

diff_runs.py compared almost nothing. Its TRACKED_FIELDS were
tiktok-profile-scraper's account columns, 26 of which Advertisement
does not have, so a diff of two runs reported "0 changed" whenever only
an ad's run dates, review status or audience changed. It now tracks this
repo's own columns and prints each run's share of the library's
per-region total. smoke_test.py pins every tracked name against the
dataclass and checks that a changed column is actually reported.

A copied .env.example set TIKTOK_URL=nasa, a TikTok handle, which
is not a region. It is now DE.

  • Donor prose removed from the shared core. output_writer.py,
    diff_runs.py, the engines, page_flow.py, smoke_test.py,
    .github/ci_checks.py and the Dockerfile carried text from the repos
    this core was copied from — YouTube comment threads, --sort top,
    reply threads, job listings, "the business", --mode comments --out software-engineer — describing those sites as if they were this one.
    Rewritten from this repo's own README, code and fixtures, or deleted
    where there was no measured equivalent. Explicit sibling provenance
    ("measured on tiktok-profile-scraper's route", "a sibling repo
    (youtube-scraper) had…") is kept and now says whose it is.

  • output_writer.py's docstring described --mode profile and account
    statistics; page_flow.py, the engines and smoke_test.py described a
    profile page, an account, video_unavailable and the embed window. All
    now describe the Ad Library (or are gone).

  • The engines' _rotate_if_per_page said nothing one fetch receives feeds
    the next; on this route the search_id cursor does, and it now says so.

  • smoke_test.py's run_meta test data is an ads run on
    library.tiktok.com rather than a profile run on @nasa.

  • .github/ci_checks.py no longer exempts an avatar_id column this repo
    does not have from the credential scan.

  • captcha_solver.py's docstring pointed at a "No DataDome solver" section
    that does not exist in this repo (it came with the copied core). Removed.

  • The Scraper API engine failed on every --wait-text / --wait-element /
    --wait-state call, and was billed for it.
    It sent waitFor as a
    JSON-encoded string; measured 2026-09-23 the live API answers that with
    HTTP 422 "params.waitFor must be an object" and still charges $0.0005,
    while the same request with an object is answered 200. It is now sent as
    an object. (The target status was already read from http_code; the new
    regression check pins that too, driving the real fetch_html with
    requests.post stubbed.)

  • --wait-state networkidle is refused by the Scraper API (HTTP 422
    "params.waitFor.state must be one of: load, domcontentloaded", still
    billed — measured 2026-09-23 on a sibling repo with the object-shaped
    waitFor). The choice is removed.

v0.1.1

Choose a tag to compare

@jehrr jehrr released this 23 Sep 14:01
90a2738

Correction to v0.1.0. Its captcha_solver.py docstring described a
2Captcha captcha-solving method for TikTok as available. That method is
deprecated, and the text no longer offers it. The challenge policy for
TikTok's slide puzzle now says solve: False, which matches what the
code does: no solver for it is implemented.

v0.1.0

Choose a tag to compare

@jehrr jehrr released this 23 Sep 09:24

First release. Reads TikTok's EU Ad Library — the transparency endpoint
TikTok serves without a key, an account or a proxy.

One header gates the whole thing

Measured 2026-09-22 from a bare datacentre address (Hetzner, Helsinki):

with the browser's headers                         HTTP 200, 12 ads
the same, minus `x-ccl-str`                        HTTP 421
content-type + user-agent + referer + x-ccl-str    HTTP 200, 12 ads

That header is minted by the library's own JavaScript — there is no global
to read it from, and a plain fetch issued from inside the page gets 421
too. So a browser is a PREREQUISITE here rather than a fallback, which is
the reverse of this repo's two siblings, and --transport http is refused
up front with that reason.

The decoys

  • offset does nothing. The body carries one, the library's own UI
    increments it, and offsets 0, 12 and 24 returned the identical twelve
    ads in the identical order. Pagination is by a base64 search_id
    cursor, and the END of the listing is read from that cursor rather than
    from has_more — a cursor that stops advancing ends the run.
  • limit does nothing. 12, 50 and 100 all return twelve.

A scraper that trusted either would report a complete run of duplicates.

The bug this release found in itself

An ad id is not unique. An EU ad buy commonly runs in several member
states at once and the library lists it under each. Measured, page one of
five regions within the same few seconds:

DE vs IT   11 of 12 ad ids shared
DE vs FR    9 of 12
DE vs PL    9 of 12
DE vs GB    1 of 12      <- outside the EU, bought separately

Deduping on sku across regions therefore DESTROYS data, and it did: a
two-region run collapsed France's twelve ads to two. Every row now carries
row_key ({region}:{ad_id}), the engines dedupe on it and diff_runs.py
joins on it.

Complete is not exhaustive, and here the gap is the largest in the family

The library reports 17,343,646 ads for Germany alone and serves twelve per
request — a hundred-page run holds 0.0069%. Every sidecar records
site_total_per_region, ads_per_region, sample_share_pct and
why_each_region_stopped, and the closing log prints the fraction in
words.

Also found while building

  • rejection_info was order-dependent. It re-serialises a nested
    object, and without sort_keys two byte-identical responses produced
    two different strings — so a diff would report the rejection as having
    changed. Found by make_fixtures.py --verify, which parsed a capture
    and its own fixture (o == f was True) and got different rows. Same
    shape as a float32 round-trip seen on a sibling repo.
  • Timestamps are milliseconds. Read as seconds, 1790112836000 lands in
    the year 58,700.
  • Selenium needed goog:loggingPrefs at launch. It has no
    request-event API, so it captures the header from Chrome's performance
    log — and without that capability the log is empty and the failure
    message points at the Search button, which is the wrong place to look.

Deliberately not here

  • impression and spent. TikTok publishes both on every ad and both
    were empty on all 216 measured across six regions. The measurement is
    recorded in output_writer.py.
  • The 2Captcha Scraper API path. That service fetches a URL and hands
    back what the site returned; it cannot mint a header for a request it is
    not making. Refused with that reason — a feature request, not a
    limitation of the product.
  • Any region outside the 33 the library serves. --region US is
    refused as a real country the library does not cover, not as a typo.