builtins.TypeError:无效文件:正在读取xml文件-python
看起来这个方法不起作用,它返回我内置的。类型错误:无效文件:尽管内容类型返回xml数据。有什么办法解决这个问题吗?试着换一行:builtins.TypeError:无效文件:正在读取xml文件-python,python,xml,Python,Xml,看起来这个方法不起作用,它返回我内置的。类型错误:无效文件:尽管内容类型返回xml数据。有什么办法解决这个问题吗?试着换一行: import xml.etree.ElementTree as reader import requests web_data = 'http://api.worldbank.org/incomeLevels/LIC/countries' a = requests.get(web_data) print(a.headers['Content-Type']) print
import xml.etree.ElementTree as reader
import requests
web_data = 'http://api.worldbank.org/incomeLevels/LIC/countries'
a = requests.get(web_data)
print(a.headers['Content-Type'])
print(reader.parse(a).getroot())
到
a是响应对象,a.text是内容
另外,reader.parse需要一个文件名,如果要从字符串中解析,则必须使用该方法
请注意,fromstring方法已经返回xml的根元素
print(reader.parse(a).getroot())
print(reader.fromstring(a.text))