pyquery
pyquery copied to clipboard
Confused with PyQuery()
Hi:
I'm using PyQuery to extract information from xml files. But It seems PyQuery() is not act as excepted:
This Code Runs OK:
from pyquery import PyQuery
_xml = '''
<?xml verion="1.0" encoding="UTF-8"?>
<node>
<data></data>
</node>
'''
print( PyQuery(_xml) )
But If i Trimed the _xml , It raised Exception:
from pyquery import PyQuery
_xml = '''<?xml verion="1.0" encoding="UTF-8"?>
<node>
<data></data>
</node>
'''
print( PyQuery(_xml) )
Traceback (most recent call last):
File "Test.py", line 17, in <module>
print( PyQuery(_xml) )
File "C:\Python38\lib\site-packages\pyquery\pyquery.py", line 217, in __init__
elements = fromstring(context, self.parser)
File "C:\Python38\lib\site-packages\pyquery\pyquery.py", line 57, in fromstring
result = getattr(etree, meth)(context)
File "src\lxml\etree.pyx", line 3237, in lxml.etree.fromstring
File "src\lxml\parser.pxi", line 1891, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
Is this a BUG ?
As you can see the error is raised by the lxml parser so you should post another issue on this project