如何获取OUTLINE风格Material Icons的SVG文件?
Hey there! I totally get the pain of manually downloading dozens (or hundreds) of SVG icons—here are a few solid solutions to batch grab all Outline-style Material Icons without the tedious manual work:
1. Use the Official Material Icons npm Package
The easiest and most reliable way is to use the official npm package maintained by the Material Design team. It includes every icon style (including Outline) as raw SVG files:
- Open your terminal and run this command to install the package:
npm install @material-icons/svg - Once installed, head to the
node_modules/@material-icons/svg/outlinedirectory in your project. This folder has every Outline icon as an individual SVG file—you can just copy them out to use wherever you need.
2. Write a Simple Python Scraping Script
If npm isn't your thing, a quick Python script can automate the download process. Just make sure to respect the site's robots.txt and avoid sending too many requests too fast (to keep things friendly for their servers). Here's a basic example:
import requests from bs4 import BeautifulSoup import os # Create a folder to store the downloaded SVGs os.makedirs("material-outline-icons", exist_ok=True) # Fetch the Outline icons page base_url = "https://material.io/tools/icons/?style=outline" page_response = requests.get(base_url) soup = BeautifulSoup(page_response.text, "html.parser") # Extract all icon names from the page icon_items = soup.find_all("a", class_="icon-item") for item in icon_items: icon_name = item.get("data-name") # Construct the direct SVG URL (follows a consistent pattern) svg_url = f"https://fonts.gstatic.com/s/i/materialiconsoutlined/{icon_name}/v12/24px.svg" # Download and save the SVG svg_response = requests.get(svg_url) with open(f"material-outline-icons/{icon_name}.svg", "wb") as svg_file: svg_file.write(svg_response.content) print(f"Downloaded: {icon_name}.svg")
Note: If the script stops working later, the page structure or SVG URL pattern might have changed—just inspect the page to update the selectors or URL format.
3. Use a Community-Maintained GitHub Repository
While you might have missed it initially, there are trusted community repositories that mirror all Material Icons in SVG format, organized by style. Search GitHub for repos tagged with material-design-icons or material-icons—look for ones that have recent updates to ensure they include the latest icons. Most of these repos will have a dedicated outline folder with all the SVGs you need.
内容的提问来源于stack exchange,提问作者eXorcist

