css_test2.py
| 1 |
# coding=utf-8
|
|---|---|
| 2 |
|
| 3 |
from lxml.cssselect import CSSSelector |
| 4 |
from lxml.etree import fromstring |
| 5 |
|
| 6 |
sel = CSSSelector('stat[name=numDocs],stat[name=maxDoc]')
|
| 7 |
|
| 8 |
h = fromstring('''
|
| 9 |
<html>
|
| 10 |
<stat name="numDocs" >
|
| 11 |
12493806
|
| 12 |
</stat>
|
| 13 |
<stat name="maxDoc">16051125</stat>
|
| 14 |
</html>''')
|
| 15 |
|
| 16 |
#matches = [e.get('id') for e in sel(h)]
|
| 17 |
|
| 18 |
|
| 19 |
for e in sel(h): |
| 20 |
print e.tag
|
| 21 |
|
| 22 |
#print matches
|