"""
really used in fetching colors from uiGradients
"""
import re
from selenium import webdriver
import time
import os
import sys
import re
from bs4 import BeautifulSoup
import random
from selenium.webdriver.chrome.options import Options
temp_path ="uiGradients_temp.txt"
path ="uiGradients.txt"
wikiart_path = 'uiGradients' #"wikiart"
original_url = 'https://uigradients.com/' # 'https://www.wikiart.org/en/paintings-by-style/cubism?select=featured#!#filterName:featured,viewType:masonry'
# os.environ["PATH"] += os.pathsep + 'D:\google-art-downloader-master'
if not os.path.exists(wikiart_path):
os.makedirs(wikiart_path)
# option = webdriver.ChromeOptions()
# option.add_argument('--headless')
# option.add_argument('--disable-gpu')
# browser = webdriver.Chrome(chrome_options = option)
fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.set_headless()
browser = webdriver.Firefox(firefox_options=fireFoxOptions)
asserts_all=set()
mark_time = 0
last_value = 0
now_len = 0
pre_len = 0
count__all = 0
try:
browser.get(original_url)
# time.sleep(8)
pageSource = browser.page_source
# browser.find_element_by_xpath('//*[@id="app"]/section/div[1]/a').click()
soup = BeautifulSoup(pageSource,'lxml')
all_datas = soup.find_all('li', {"class":"palette__item"})
# for data in all_datas:
# for line in data.children:
# # print(line.get("style"))
# print(re.findall('rgb(.+)',line.get("style")))
except Exception as e:
print("global",e)
finally:
# with open(path,'w',encoding="utf8") as write_file:
# for line in asserts_all:
# write_file.write(str(line)+"\n")
browser.close()
all_RGB_value = list()
for data in all_datas:
for line in data.children:
# print(line.get("style"))
# print(re.findall(r'rgb\(.*\)',line.get("style"),re.S))
RGB_data = re.findall(r'rgb\(.*[^\)]\)',line.get("style"))
# print(RGB_data)
all_RGB_value.append(re.findall(r'(\w*[0-9]+)\w*',RGB_data[0]))
def rgb2hex(value):
r,g,b = value
hex = "#{:02x}{:02x}{:02x}".format(r,g,b)
return hex
# print(all_RGB_value)
all_rule_colors = list()
for lines in all_RGB_value:
temp_values = list()
rule_temp_values= list()
for index, value in enumerate(lines):
temp_values.append(int(value))
if (index + 1)%3 == 0:
# print(temp_values)
# print(temp_values)
# print(rgb2hex(temp_values))
rule_temp_values.append(rgb2hex(temp_values))
temp_values = []
all_rule_colors.append(rule_temp_values)
for line in all_rule_colors:
print(line)
import pandas as pd
pd.DataFrame(all_rule_colors).to_excel( wikiart_path+ "/excel_color.xlsx",index = None ,header = None)
all_rule_colors_filter = list()
for lines in all_rule_colors:
print(lines[-1])
all_rule_colors_filter.append([lines[0],lines[-1]])
import pandas as pd
pd.DataFrame(all_rule_colors_filter).to_excel( wikiart_path+ "/excel_color_filter.xlsx",index = None ,header = None)
网友评论