我试图从css URL解析一些特定的十六进制颜色值(不是所有的内容),但不知道如何使用Python来解决这个问题。你知道吗
URL如下所示:
https://abcdomain.com/styles/theme.css
其内容包括:
@charset "UTF-8";
/* CSS Document */
.bg-primary {
background-color: #2ccfff;
color: white;
}
.bg-success {
background-color: #8b88ff;
color: white;
}
.bg-info {
background-color: #66ccff;
color: white;
}
.bg-warning {
background-color: #ff9900;
color: white;
}
.bg-danger {
background-color: #7bb31a;
color: white;
}
.bg-orange {
background-color: #f98e33;
color: white;
}
我只需要解析特定条目的“background color”十六进制值,从“warning”到“orange”。你知道吗
我试过urllib.request
,但没有准确地与我合作。你知道吗
如果有人能帮助我使用Python脚本获得这些值,我将非常感激。你知道吗
谢谢你, 艾哈迈德
我在CSS代码中添加了一个额外的“f”,因为它没有验证。你知道吗
您可以使用requests下载文件,并使用cssutils解析CSS。下面的代码查找所有
background-color
实例,并使用CSS选择器将它们放入dict中。你知道吗这将打印以下结果:
相关问题 更多 >
编程相关推荐