具体使用方法如下:
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 打印
Traceback (most recent call last):File "D:\Program Files (x86)\JetBrains\PyCharm Educational Edition 1.0.1\helpers\pydev\pydev_run_in_console.py", line 66, in <module>
globals = run_file(file, None, None)
File "D:\Program Files (x86)\JetBrains\PyCharm Educational Edition 1.0.1\helpers\pydev\pydev_run_in_console.py", line 28, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:/python/xpth/xpathPractice.py", line 51, in <module>
results = pool.map(spider, page)
File "D:\anzhuang\Anaconda\lib\multiprocessing\pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "D:\anzhuang\Anaconda\lib\multiprocessing\pool.py", line 558, in get
raise self._value
IndexError: list index out of range123456789101112123456789101112
出现如上所示的错误:
IndexError 下标索引超出序列边界,比如当x只有三个元素,却试图访问x[5]
<div class="tB-r" id="tB-r"><div>
标书下载截止时间: <span class="span-v" data-key="标书下载截止时间"></span>
</div>
<div id="oxe">
保证金缴纳截止时间: <span class="span-v" data-key="保证金缴纳截止时间"></span>
</div>
<br>
<div>
质疑截止时间: <span class="span-v" data-key="质疑截止时间"></span>
</div>
<div>
&emsp&emsp&emsp&emsp&emsp开标时间: <span class="span-v" data-key="开标时间"></span>
</div>
</div>