[英]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代码? 这样我就可以使用'#%02x%02x%02x' % (rgb)
来获取颜色代码? 帮助! 帮助! 帮助!
您想将 rgba 元组转换为十六进制值,这非常简单,这里有一些代码向您展示了如何实现它: https : //pythonjunkie.wordpress.com/2012/07/19/convert-hex-颜色值到 rgb-in-python/
def rgb_to_hex(rgb): ... return '%02x%02x%02x' % rgb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.