相关疑难解决方法(0)

解析XML文件获取UnicodeEncodeError(ElementTree)/ ValueError(lxml)

我向CareerBuilder API发送GET请求:

import requests

url = "http://api.careerbuilder.com/v1/jobsearch"
payload = {'DeveloperKey': 'MY_DEVLOPER_KEY',
           'JobTitle': 'Biologist'}
r = requests.get(url, params=payload)
xml = r.text
Run Code Online (Sandbox Code Playgroud)

并获得一个看起来像这样的XML .但是,我无法解析它.

使用其中之一 lxml

>>> from lxml import etree
>>> print etree.fromstring(xml)

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    print etree.fromstring(xml)
  File "lxml.etree.pyx", line 2992, in lxml.etree.fromstring (src\lxml\lxml.etree.c:62311)
  File "parser.pxi", line 1585, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:91625)
ValueError: Unicode strings with encoding declaration are not supported.
Run Code Online (Sandbox Code Playgroud)

要么 ElementTree:

Traceback (most recent call last):
  File …
Run Code Online (Sandbox Code Playgroud)

python xml lxml elementtree python-requests

5
推荐指数
2
解决办法
6071
查看次数

标签 统计

elementtree ×1

lxml ×1

python ×1

python-requests ×1

xml ×1