-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrawler.py
More file actions
52 lines (38 loc) · 1.53 KB
/
crawler.py
File metadata and controls
52 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from bs4 import BeautifulSoup
import urllib.request
import fnmatch
import requests
import os
list_link = []
# gathering all links of all catologue page
for i in range(1, 48): # max page of the site
resp = urllib.request.urlopen("https://fontlibrary.org/en/catalogue?order=&page=" + str(i))
soup = BeautifulSoup(resp, from_encoding=resp.info().get_param('charset'))
print("Scraping page " + str(i) + "/48 ...")
for link in soup.find_all('a', href=True):
list_link.append(link['href'])
# filtering to have only font links
filtered = fnmatch.filter(list_link, 'https://fontlibrary.org/en/font/*')
# remove duplicate
filtered = list(set(filtered))
print("Found " + str(len(filtered)) + " font link")
filtered_download = []
# gathering all download links of all font link
for i in range(len(filtered)):
html = requests.get(filtered[i]).text
soup = BeautifulSoup(html)
tags = soup.findAll("a", href=True)
list_download = []
for link in tags:
list_download.append(link['href'])
# filtering to have only download link
filtered_download.extend(fnmatch.filter(list_download, '/assets/downloads/*'))
print("Getting download link " + str(i))
# remove duplicate
filtered_download = list(set(filtered_download))
# download font zip to directory /home/user/Download/
for url in filtered_download:
url_link = "https://fontlibrary.org/" + url
print('Downloading %s' % url_link)
os.system('wget %s -P /home/user/Download/' % url_link)
filtered_download = []