데비안 6 설정이 너무 많습니다.lxml의 문제점
$ python --version
Python 2.6.6
$ dpkg --list|grep lxml
ii python-lxml 2.2.8-2
임과 같이 XPath를에 액세스하려고 : 나는 오류
Traceback (most recent call last):
File "a.py", line 4, in <module>
for e in root.findall('.//rec/data/field[@name="id"]'):
File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 647, in findall
return self._root.findall(path)
File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 355, in findall
return ElementPath.findall(self, path)
File "/usr/lib/python2.6/xml/etree/ElementPath.py", line 198, in findall
return _compile(path).findall(element)
File "/usr/lib/python2.6/xml/etree/ElementPath.py", line 176, in _compile
p = Path(path)
File "/usr/lib/python2.6/xml/etree/ElementPath.py", line 93, in __init__
"expected path separator (%s)" % (op or tag)
SyntaxError: expected path separator ([)
있어
import xml.etree.ElementTree as ET
root = ET.parse("a.xml")
for e in root.findall('.//rec/data/field[@name="id"]'):
print(e.tag + " " + e.attrib.get('name'))
이 파이썬 lxml이 2.2.8에 의해이 된 XPath 구문을 지원하지 않습니다?
이 버전을 지원하는 버전은 python 2.6과 호환됩니까?
제목은 약 lxml이지만 코드는 xml을 사용합니다. 또한 코드는 Python 2.7에서 작동합니다. Python 2.6에만 문제가 있는지 확실하지 않습니다. –
확인되었습니다. Python 2.6의 ElementTree는 속성 [@attribute] 구문 검색을 지원하지 않습니다. http://stackoverflow.com/questions/15753714/elementtree-syntaxerror-expected-path-separator –