python 使用css 需要导入什么模块

html-css012

python 使用css 需要导入什么模块,第1张

python 使用css 需要导入cssutils,最新版本是1.0.1。

具体使用方法如下:

1、执行以下命令安装最新版本的cssutils

easy_install cssutils

2、在代码中用import命令导入

import cssutils

3、使用cssutil内部一些选择器等的方法

指定命名空间

@namespace html "http://www.w3.org/1999/xhtml"

设置背景色为白色

@variables { BG: #fff }

html|a { color:redbackground: var(BG) }'''

sheet = cssutils.parseString(css) 开始解析css

sheet.encoding = 'ascii'

sheet.namespaces['xhtml'] = 'http://www.w3.org/1999/xhtml'

sheet.namespaces['atom'] = 'http://www.w3.org/2005/Atom'

sheet.add('atom|title {color: #000000 !important}')

sheet.add('@import "sheets/import.css"')

print sheet.cssText 打印

报错:

NotImplementedError: Cannot execute CSS selectors because the soupsieve package is not installed.

是这个函数

def fetch_city_weather_url_list(url):

    city_url_list = []

    resp = requests.get(url)

    resp.encoding = 'utf-8'

    bs = BeautifulSoup(resp.text,'lxml')

    # a_s = bs.find('a')

    a_s = bs.select('div.conMidtab a')

因为是自学,有些知识不系统,在网上搜索很久没找到答案,后来回朋友才知道