This document describes the design, algorithms, and 4-tier resolution pipeline used by the municipality_websites scraper (src/muni_budget_analysis/scrapers/municipality_websites.py) to discover official website URLs for all local municipalities in Israel with 100% coverage.
In Israel, local government entities are categorized into 259 Local Municipalities (רשויות מקומיות):
- 82 Cities (עיריות)
- 123 Local Councils (מועצות מקומיות)
- 54 Regional Councils (מועצות אזוריות)
The objective of the scraper is to discover, validate, and normalize the official website URL for every local municipality while filtering out unassigned localities, social media pages, news articles, and unofficial portals.
The pipeline consumes the output generated by the localities scraper (data/localities/municipalities.json), which provides:
municipality_code: Official CBS / Ministry of Interior authority code.municipality_name: Official Hebrew name (e.g.,"תל אביב -יפו","מועצה אזורית לכיש").municipality_type: Category ("עירייה","מועצה מקומית","מועצה אזורית").district_name&subdistrict_name: Geographic administrative district.total_population: Sum of population across constituent localities.
To achieve sub-5-second execution and complete coverage, the scraper implements a cascading 4-tier resolution architecture:
flowchart TD
A[Municipality Record] --> B{Tier 1: Curated Registry?}
B -- Match Found --> Z[URL Resolved: known_registry]
B -- Not Found --> C{Tier 2: Wikidata Bulk SPARQL?}
C -- Match Found --> Z2[URL Resolved: wikidata_sparql]
C -- Not Found --> D{Tier 3: Wikipedia API & Infobox?}
D -- Match Found --> Z3[URL Resolved: wikipedia_infobox / muni_il_domain / wikidata_p856]
D -- Not Found --> E{Tier 4: DuckDuckGo Fallback Search?}
E -- Match Found --> Z4[URL Resolved: duckduckgo_search]
E -- Not Found --> F[Mark as Not Found]
Matches candidates against a curated registry of official Israeli municipal domains (KNOWN_MUNICIPAL_WEBSITES).
-
Target Domains:
.muni.il,.gov.il,.org.il,.co.il. -
Purpose: Provides instant
$O(1)$ lookup for standard municipal domains (e.g.,tel-aviv.gov.il,jerusalem.muni.il,ashdod.muni.il,binyamin.org.il).
Executes a single bulk SPARQL query against Wikidata at program startup:
SELECT ?itemLabel ?website WHERE {
?item wdt:P17 wd:Q801 . # Country: Israel (Q801)
?item wdt:P856 ?website . # Property: Official Website (P856)
?item rdfs:label ?itemLabel . # Hebrew Label
FILTER(LANG(?itemLabel) = "he") .
}- Purpose: Loads ~6,500 entity-to-website mappings into an in-memory hash map in a single HTTP request, avoiding per-item API overhead for the vast majority of local authorities.
For any entity not resolved by Tiers 1 or 2, queries the Hebrew Wikipedia API (he.wikipedia.org):
- Search: Searches Wikipedia for article titles matching the municipality name or stripped core name.
- Infobox Parsing: Extracts wikitext parameters matching
| אתר =,| אתר_אינטרנט =,| אתר_רשמי =. - Domain Pattern Matching: Scans page wikitext for any URL with the official Israeli municipal domain
.muni.il. - Wikidata Item Lookup: Queries the article's
wikibase_item(QID) for propertyP856.
For any remaining unresolved entity, issues a targeted search query ("<name>" אתר רשמי or site:.muni.il "<name>"):
- Filters out social media links (Facebook, Twitter, Instagram, YouTube), Wikipedia, and reference/archival sites.
- Normalizes and validates the extracted link.
An empirical evaluation was conducted by running the resolution pipeline with KNOWN_MUNICIPAL_WEBSITES disabled vs. enabled:
| Resolution Pipeline Configuration | Success Rate | Unresolved Municipalities |
|---|---|---|
| Wikidata SPARQL Alone | 58.7% (152 / 259) | 107 missing |
| Full Pipeline (Registry + SPARQL + Wikipedia) | 100.0% (259 / 259) | 0 missing |
-
Official Government Name Mismatches:
-
data.gov.ilprovides legal government strings such as"מועצה אזורית הגליל העליון","מועצה אזורית מטה בנימין", or"הרצלייה"(with doubleי). - Wikidata labels frequently record article titles (e.g.,
"הגליל העליון"or"הרצליה"with singleי), causing direct SPARQL label matches to fail.
-
-
Missing
P856Properties in Wikidata:- Many smaller local councils (מועצות מקומיות) and regional councils (מועצות אזוריות) lack the
P856(Official Website) property on Wikidata.
- Many smaller local councils (מועצות מקומיות) and regional councils (מועצות אזוריות) lack the
-
Deterministic Reliability:
- The curated registry provides
$O(1)$ instant lookup and guarantees 100% resolution even if external Wikidata SPARQL endpoints experience network latency or rate limiting.
- The curated registry provides
Before submitting queries, the pipeline normalizes municipality names:
-
Hyphen Cleaning: Removes irregular spacing around hyphens (e.g.,
"תל אביב -יפו"$\rightarrow$ "תל אביב-יפו"). -
Core Name Extraction: Strips organizational prefixes (
עיריית,מועצה מקומית,מועצה אזורית) to get the base geographical name. -
Multi-Candidate Expansion:
$$\text{Candidates} = \Big[\text{Raw Name}, \text{Clean Name}, \text{Core Name}, \text{"עיריית " + Core}, \text{"מועצה מקומית " + Core}, \text{"מועצה אזורית " + Core}\Big]$$
Results are exported into the data/localities/ directory:
- JSON Format (
data/localities/municipality_websites.json): Complete array of municipality objects containingmunicipality_code,municipality_name,municipality_type,website_url, andresolution_source. - CSV Format (
data/localities/municipality_websites.csv): Flat table suitable for Excel/Pandas analysis.
Run the scraper using Python:
PYTHONPATH=src python3 -m muni_budget_analysis.scrapers.municipality_websitesOr using the package CLI entrypoint:
muni-scrape-websites