File indexing completed on 2025-01-05 04:00:27
0001 import urllib.request 0002 0003 0004 if __name__ == "__main__": 0005 from lxml import etree 0006 uri = "https://www.w3.org/TR/css-color-3/" 0007 0008 html = etree.parse(urllib.request.urlopen(uri), etree.HTMLParser()) 0009 0010 print("color_table = {") 0011 0012 names = set() 0013 0014 for row in html.findall(".//table[@class='colortable']//tr"): 0015 if row.find(".//dfn") is None: 0016 continue 0017 0018 name = row.xpath(".//dfn/text()")[0] 0019 0020 if name in names: 0021 continue 0022 0023 names.add(name) 0024 rgb = list(map(lambda x: int(x)/255, row.xpath(".//td[last()]/text()")[0].strip().split(","))) 0025 rgb.append(1) 0026 print(' "%s": %s,' % (name, rgb)) 0027 0028 print("}")