-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscraper.py
More file actions
57 lines (45 loc) · 1.52 KB
/
scraper.py
File metadata and controls
57 lines (45 loc) · 1.52 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
53
54
55
56
57
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import csv
#Color code possibilities
baseColor=["Y","R"]
fristNumber=[ str(k) for k in range(1,6)]
secondNumber=["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15"]
colorCode=[]
#Color code generation
for i in fristNumber:
for j in baseColor:
for k in secondNumber:
colorCode.append(i+j+k)
#Csv generation parameters
fields=["Pantone Code","hexacode","red","green","bleu"]
row=[]
for k in colorCode:
try:
#Search Resquest on Encycolorpedia for PantoneSkinTone Color guide
req = Request(
url="https://encycolorpedia.fr/search?q="+k,
headers={'User-Agent': 'Mozilla/5.0'}
)
#Find all url in the website
source = urlopen(req).read()
soup = BeautifulSoup(source,'lxml')
urllist=soup.find_all('a')
string=urllist[len(urllist)-1]
#Exatact and convert HexaColorCode and convert to RGB
if k in str(string):
hexacode=str(string)[10:16]
red=int(hexacode[0:2],16)
green=int(hexacode[2:4],16)
bleu=int(hexacode[4:6],16)
row.append([k,hexacode,red,green,bleu])
print(k+" succed")
else:
print(k+" no exist")
except:
print("Fail"+" "+k)
#Write result in a csv File
with open('PantoneSkinTone.csv', 'w') as f:
write = csv.writer(f)
write.writerow(fields)
write.writerows(row)