← back to Uspto Trtyrap

dl_one.py

17 lines

from curl_cffi import requests
import json,sys
cookie=open('.cookie').read().strip()
base="https://data.uspto.gov/ui/datasets/products/files/TRTYRAP/"
name="apc18840407-20251231-1.zip"
H={"Accept":"application/json","Referer":"https://data.uspto.gov/bulkdata/datasets/trtyrap","Cookie":cookie}
r=requests.get(base+name, headers=H, impersonate="chrome", timeout=60)
print("sign step:", r.status_code, r.headers.get("content-type"), "len", len(r.content))
try: loc=r.json().get("Location")
except Exception: print("no json:", r.text[:80]); sys.exit(1)
print("got signed URL:", bool(loc))
# now download the signed URL with chrome impersonation
r2=requests.get(loc, headers={"Referer":"https://data.uspto.gov/","Cookie":cookie}, impersonate="chrome", timeout=300, stream=True)
print("file step:", r2.status_code, r2.headers.get("content-type"), "clen", r2.headers.get("content-length"))
first=next(r2.iter_content(chunk_size=8), b"")
print("magic:", first[:4].hex(), "(504b0304 = PK zip)")