Skip to content

Instantly share code, notes, and snippets.

@Pymmdrza
Created March 13, 2024 20:09
Show Gist options
  • Save Pymmdrza/5f4dc0df74c789b2fbd7903161efb194 to your computer and use it in GitHub Desktop.
Save Pymmdrza/5f4dc0df74c789b2fbd7903161efb194 to your computer and use it in GitHub Desktop.
Download Free Icon SVG Automatic With Python From SVGREPO
import requests, requests_random_user_agent
from colorthon import Colors as Fore
from bs4 import BeautifulSoup
import os
total = 0
def downloader(urlFull, fldrN):
nm = urlFull.split("/")[-1]
if not os.path.exists(fldrN):
os.makedirs(fldrN)
req = requests.get(urlFull)
pathFuller = f"{fldrN}/{nm}"
with open(pathFuller, "wb") as f:
f.write(req.content)
global total
total += 1
print(
f"[+] {Fore.CYAN}{total}{Fore.RESET} {Fore.GREEN}Downloaded:{Fore.RESET}{Fore.YELLOW} {pathFuller}{Fore.RESET}")
def getUrl(addr, pageNumber=1):
fx = []
if addr[-1] == '/':
fld_name = addr.split('/')[-2]
else:
fld_name = addr.split('/')[-1]
page_number = 1
while True:
page_addr = f"{addr}/{page_number}/"
resp = requests.get(page_addr)
html_content = resp.text
soup = BeautifulSoup(html_content, 'html.parser')
svg_links = []
def_addr = "https://www.svgrepo.com/show/"
for link in soup.find_all('a'):
href = link.get('href')
svg_links.append(href)
for o in svg_links:
first_u = o
second = first_u.split("/")
if first_u.startswith("/svg/"):
nameul = f"{second[2]}/{second[3]}.svg"
url_full = f"{def_addr}{nameul}"
if url_full not in fx:
fx.append(url_full)
downloader(url_full, fld_name)
else:
continue
# Check if there are less than 50 icons in the current page
if len(svg_links) < 50:
break # Break the loop if less than 50 icons are found
page_number += 1 # Move to the next page
enterpage = str(input("Enter URL For DL [e.x: https://www.svgrepo.com/collection/gradient-line-icons/]: "))
page = str(input("Total Page [Default: 1]: "))
if page:
pg = int(page)
if pg > 1:
for i in range(pg):
getUrl(enterpage)
else:
getUrl(enterpage)
getUrl(enterpage)
print("Done!")
@Pymmdrza
Copy link
Author

Pymmdrza commented Mar 13, 2024

package's

windows:

pip install colorthon requests-random-user-agent bs4

linux :

pip3 install colorthon requests-random-user-agent bs4

screen record from svg repo auto download collection

SVGRepo_Screenrecord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment