Use Patch.com Local News, Events & Classifieds Finder with Python
Search Patch.com's hyperlocal US news by keyword, town, category, author, or tag, and browse its local events calendar or classifieds board, with date-range and distance filters.
1. Choose the data you need
Review the published README for supported collection modes, examples, and limits. The recipe below uses the current published input definition.
2. Prepare a source-based input
This JSON contains published prefills and required-field defaults. Review every value for your task before running it; it is not a promise of successful collection.
{
"authorName": "",
"category": "",
"classifiedCategory": "",
"includeBodyText": false,
"includeDetails": false,
"maxDetails": 0,
"maxItems": 3,
"mode": "search",
"monitorKey": "",
"monitorMode": false,
"radiusMiles": 25,
"regionSlug": "",
"searchMatch": "allWords",
"searchQuery": "city council",
"sortBy": "relevance",
"tagName": "",
"townSlug": ""
}
Download input.example.json and save your reviewed copy as input.json.
| Field | Type | Required | Description |
|---|---|---|---|
mode | string | required | What to fetch from Patch.com. |
startUrls | array | optional | mode=byUrl only. Paste Patch article, event, classified, town, category/topic, state or search URLs. Article/event/classified URLs are scraped directly; town/topic/state/search URLs are converted into the equivalent scoped query. |
searchQuery | string | optional | Free-text keyword to search for (mode=search; also applies to mode=events/classifieds and to scope URLs). Leave empty to browse the newest articles matching the other filters. |
searchMatch | string | optional | How multi-word searches match. "All words" requires every word anywhere in the headline/summary/topic (more results). "Exact phrase" requires the words to appear together (the old behavior). |
authorName | string | optional | Exact byline/reporter/poster name (required for mode=byAuthor; on any other mode it is an extra server-side filter). Copy it from this actor's `author` output field, e.g. "Eric Heyl". |
tagName | string | optional | Exact editorial tag (required for mode=byTag; on article modes it is an extra filter). Copy it from this actor's `tags` field, e.g. "Back To School". Only a minority of articles carry tags. |
regionSlug | string | optional | US state/edition to scope results to (required for mode=byTown; optional filter on every other mode). "Across America" is Patch's national edition (code US); "US Territories" is a valid Patch region with no current articles. |
townSlug | string | optional | Patch town/city URL slug (required for mode=byTown; requires regionSlug too). Find it in a Patch URL, e.g. patch.com/california/santamonica -> "santamonica". Example: "santamonica" (with regionSlug=california). |
category | string | optional | News category/topic to filter by (required for mode=byCategory; optional filter on mode=search/byTown/byAuthor/byTag). Not applicable to mode=events/classifieds -- use `classifiedCategory` for mode=classifieds instead. |
classifiedCategory | string | optional | Classifieds category to filter by (mode=classifieds only; a completely separate value set from `category`, which is news-only). Leave as "(any category)" to browse every classified category. |
sortBy | string | optional | Order of results. "Nearest first" requires both `nearLat`/`nearLng` AND mode=search/byTown/byCategory/byAuthor/byTag (news); otherwise it falls back to Relevance. "Soonest event first" requires mode=events; on any other mode it also falls back to Relevance. |
publishedAfter | string | optional | Only include articles/events/classifieds posted to Patch on or after this date (i.e. listing date, not an event's own occurrence date -- see `eventDateAfter` for that). Format: YYYY-MM-DD. Combine with `publishedBefore` for a date range. |
publishedBefore | string | optional | Only include articles/events/classifieds posted to Patch on or before this date. Format: YYYY-MM-DD. Combine with `publishedAfter` for a date range. |
eventDateAfter | string | optional | mode=events only. Only include events occurring on or after this date (the event's own date, not when it was posted to Patch -- see `publishedAfter` for that). Format: YYYY-MM-DD. Combine with `eventDateBefore` for a date range, e.g. "what's happening this weekend". |
eventDateBefore | string | optional | mode=events only. Only include events occurring on or before this date. Format: YYYY-MM-DD. Combine with `eventDateAfter` for a date range. |
nearLat | number | optional | Latitude of a point to search near (combine with `nearLng` and `radiusMiles`). News modes only (search/byTown/byCategory/byAuthor/byTag) -- not available for mode=events/classifieds, whose Patch indexes don't expose a filterable location field. Both `nearLat` and `nearLng` must be set together; otherwise this filter is ignored. |
nearLng | number | optional | Longitude of a point to search near (combine with `nearLat` and `radiusMiles`). News modes only -- see `nearLat` description. Both `nearLat` and `nearLng` must be set together; otherwise this filter is ignored. |
radiusMiles | integer | optional | Search radius around `nearLat`/`nearLng`, in miles. News modes only -- see `nearLat` description. Ignored unless both `nearLat` and `nearLng` are set. |
includeBodyText | boolean | optional | Add bodyHtml (the original HTML), bodyText (readable plain text) and bodyLength to each record. Article/event/classified bodies come from Patch's own search payload, so this costs no extra request. |
includeDetails | boolean | optional | Fetch each record's Patch page and add gallery images/captions/credits, author avatar and points, comment/reply counts, breaking/sponsored flags, town grade/weekly views/ZIPs/timezone/county/metro, event venue/type/website, and classified contact state. One extra request per record; failed pages never discard the base record. |
maxDetails | integer | optional | How many records to enrich when `includeDetails` is on. 0 means every emitted record (up to `maxItems`). Ignored when detail enrichment is off. |
monitorMode | boolean | optional | Emit only records whose Patch ID has not been seen by an earlier run with the same monitor key. State is stored in the actor's key-value store. |
monitorKey | string | optional | Optional namespace for monitor state. Give different saved tasks different keys to keep their seen-ID lists separate. Derived automatically from the mode and filters when empty. |
maxItems | integer | optional | Maximum number of articles, events or classifieds to return (1-1000). Requests above 250 are automatically split into date partitions to bypass Patch's 250-hit search-key window. |
3. Start an Actor run
Set APIFY_TOKEN in your environment. Python 3.10 or newer is sufficient; this recipe uses no third-party packages.
Execution may incur charges. Review current pricing on Apify. The request asks for a 120-second timeout and a charge limit; these settings are subject to Apify’s pricing and do not guarantee an all-inclusive spending cap.
import json
import os
import urllib.request
# Save the schema-derived example as input.json; review and edit it first.
with open("input.json", encoding="utf-8") as stream:
actor_input = json.load(stream)
token = os.environ["APIFY_TOKEN"]
request = urllib.request.Request(
"https://api.apify.com/v2/acts/C5BexVLa39ZcPgizT/runs?timeout=120&maxTotalChargeUsd=0.50",
data=json.dumps(actor_input).encode("utf-8"),
headers={"Authorization": "Bearer " + token, "Content-Type": "application/json"},
method="POST",
)
# This starts a potentially billable run. Do not automatically retry this POST.
with urllib.request.urlopen(request, timeout=40) as response:
run = json.load(response)["data"]
print("Run ID:", run["id"])
print("Status:", run["status"])
# Inspect and download results in Apify Console once the run succeeds.
4. Inspect the actual results
Open the run in Apify Console and wait for a successful completion. Use the published output schema to locate results and the dataset schema to understand declared views. Missing or optional record fields must not be treated as guaranteed values.
Hyperlocal Patch.com articles, events and classifieds with headline, summary, full body text, author, dates, town/category metadata, coordinates, media and optional detail-page enrichment.
Questions before you run
Which inputs are required?
The published required fields are mode
What does this guide verify?
The fields, prefills, and schema links are rendered from the published build. This is a usage recipe, not a paid live extraction test. Source availability and collection results can vary.
What if the run request times out?
Check Apify Console before retrying. The first request may already have created a run. Do not automatically repeat a run-creation POST.
Generated from source build kgvnqgKSosfpPzZC4 and its README and schemas. Source changes regenerate this guide; no third-party editorial claims are inferred.