【发布时间】:2017-09-08 08:02:40
【问题描述】:
我正在尝试通过“请求”库使用 python 3.4 从某些 Web 服务中获取数据。我需要获取一个有效的 xml 字符串来使用“lxml”库进行解析。但由于某种原因,xml 中的数据编码不正确:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<xmlData>
<?xml version="1.0" encoding="UTF-8"?><Response><Data& gt;<Company>... etc.
</xmlData>
</soap:Body>
</soap:Envelope>
使用以下代码:
ssession = requests.Session()
session.get(target_url)
exml = session.post(target_url, data=__xml, headers=headers)
print(exml.text)
如何在 XML 中提取没有像“>”这样的符号的数据?如果不手动将&gt; 符号替换为等效符号,这是否可行?
【问题讨论】: