文章詳情頁
Python 如何從 css 文件中提取所有 ID 名和 CLASS 名
瀏覽:113日期:2022-06-26 15:26:11
問題描述
有個需求,從 css 文件中提取所有 ID 名和 CLASS 名到兩個 list 中
用正則可以準(zhǔn)確的實現(xiàn)這個功能么?
classValues = re.findall(r’.([w_-]+)’,content) idValues = re.findall(r’#([w_-]+)’,content)
但是會多出好多并不屬于 ID 和 class 的值, 比如下面情況:
background-color: #fff; -webkit-box-shadow: 0 0 2px 0 rgba(31, 31, 31, 0.07);
問題解答
回答1:re.findall(’.(.+){’, content) re.findall(’#(.+){’, content)
相關(guān)文章:
1. nignx - docker內(nèi)nginx 80端口被占用2. angular.js - angularjs的自定義過濾器如何給文字加顏色?3. android-studio - Android studio導(dǎo)入老版本的2048項目報錯4. 為什么return不了數(shù)據(jù)給ajax5. java - mybatis里的REGEXP6. PhpStorm 輸入php按tab后生成的起始結(jié)束標(biāo)簽<php><php> 如何修改?7. PHP 怎么api獲取json數(shù)據(jù)8. PHP類屬性聲明?9. php mail無法發(fā)送郵件10. 做一個抽獎系統(tǒng)
排行榜

熱門標(biāo)簽