Files

44 lines
1.2 KiB
Python

import os
import json
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse
URL = "https://material-theme.com/docs/reference/associations/"
DATA_FILE = "icons.json"
def scrape_icons():
print(f"Connecting to {URL}...")
response = requests.get(URL)
soup = BeautifulSoup(response.text, 'html.parser')
rows = soup.select("tbody tr")
associations = []
print(f"Found {len(rows)} potential icons. Starting download...")
for row in rows:
cols = row.find_all("td")
if len(cols) < 4:
continue
name = cols[0].get_text(strip=True)
pattern = cols[1].find("code").get_text(strip=True) if cols[1].find("code") else cols[1].get_text(strip=True)
img_tag = cols[3].find("img")["src"]
associations.append({
"name": name,
"pattern": pattern,
"icon_path": img_tag
})
print(f"Saved: {name}")
with open(DATA_FILE, 'w', encoding='utf-8') as f:
json.dump(associations, f, indent=4)
print(f"\nFinished! Processed {len(associations)} icons.")
print(f"Data saved to {DATA_FILE}")
if __name__ == "__main__":
scrape_icons()