I thought it would be fun to create python program that scrapes colors from websites. So I did.
I am not very used to python, so python was an obvious choice.
So what my litte program does is:
- requesting a html page from the given url
- looking for link tags to find css - using regular expressions
- requesting that css
- parsing css for color values - again some regular expressions magic :sparkles:
- converting those color values to rgb (used colorsys for that)
A small snippet, how this program may be used:
url = 'https://timobechtel.com' handler = RequestHandler(url) html = handler.get() html_parser = HTMLStyleParser(html) css = html_parser.load_css(handler) color_parser = CSSColorsParser(ColorGenerator()) colors = color_parser.parse_colors(css) for color in colors: print(color.hex_string())
#243444 #fdfdfd #ce480a #852f06 #243444 #47596c [...]
I might upload this to Github later, if there’s interest.