Created
December 7, 2017 15:31
-
-
Save tokawpl/3057e2a9d8c13a130d8042d1f2af3a47 to your computer and use it in GitHub Desktop.
code snippet for getting all "hsl"-values with their corresponding name from http://htmlcolorcodes.com/color-names/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zlib | |
from urllib import request | |
from bs4 import BeautifulSoup | |
resource = request.urlopen("http://htmlcolorcodes.com/color-names/") | |
content = resource.read() | |
decompressed_content = zlib.decompress(content, 16+zlib.MAX_WBITS) | |
soup = BeautifulSoup(decompressed_content, "html.parser") | |
color_classes = ["red", "pink", "orange", "yellow", "purple", "green", "blue", "brown", "white", "gray"] | |
color_sections = [] | |
for color in color_classes: | |
color_sections += soup.find_all("section", id=color) | |
for section in color_sections: | |
rows = section.find_all("tr", class_="color") | |
for row in rows: | |
color_name = row.find_all("h4", title="HTML color name").pop().string.lower() | |
hsl = row.find_all("div", class_="js-color").pop().get("data-hsl") | |
print("$%s: hsl(%s) !default" % (color_name, hsl)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment