如何将Python中的RGBA转换为RGB,或者如何得到正确的颜色代码
How to convert RGBA to RGB in Python, or how to get the right color code
提前致谢!
下面是html,我用driver.find_element_by_xpath("//h3[@class='title-part form_title']").value_of_css_property('color')
去抓颜色,结果是rgba(63,64,64,1)
,但我期望的结果是#3f3f40。
问题1:有什么方法可以直接通过python得到正确的色码?
问题2:如果不是,有没有办法把rgba(63,64,64,1)转成rgb码?这样我就可以 user'#%02x%02x%02x' % (rgb)
获取颜色代码?
帮助!帮助!求助!
您想将 rgba 元组转换为十六进制值,这非常简单,这里有一些代码向您展示了如何实现它:https://pythonjunkie.wordpress.com/2012/07/19/convert-hex-color-values-to-rgb-in-python/
def rgb_to_hex(rgb):
... return '%02x%02x%02x' % rgb
提前致谢!
下面是html,我用driver.find_element_by_xpath("//h3[@class='title-part form_title']").value_of_css_property('color')
去抓颜色,结果是rgba(63,64,64,1)
,但我期望的结果是#3f3f40。
问题1:有什么方法可以直接通过python得到正确的色码?
问题2:如果不是,有没有办法把rgba(63,64,64,1)转成rgb码?这样我就可以 user'#%02x%02x%02x' % (rgb)
获取颜色代码?
帮助!帮助!求助!
您想将 rgba 元组转换为十六进制值,这非常简单,这里有一些代码向您展示了如何实现它:https://pythonjunkie.wordpress.com/2012/07/19/convert-hex-color-values-to-rgb-in-python/
def rgb_to_hex(rgb):
... return '%02x%02x%02x' % rgb