Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python请求xml响应_Python_Xml_Python Requests_Python Multithreading_Grequests - Fatal编程技术网

Python请求xml响应

Python请求xml响应,python,xml,python-requests,python-multithreading,grequests,Python,Xml,Python Requests,Python Multithreading,Grequests,grequests的快速问题,因为它的文档非常稀少。 从发送的请求返回xml响应的最佳方式是什么?除了状态码之外,我很难找到回复的方法。有人能给我指出正确的方向吗?grequests甚至可以返回xml响应吗?我应该只使用请求并自己执行线程吗? 这是文件代码 import grequests urls = [ 'http://www.heroku.com', 'http://python-tablib.org', 'http://httpbin.org', 'http://python-requ

grequests的快速问题,因为它的文档非常稀少。 从发送的请求返回xml响应的最佳方式是什么?除了状态码之外,我很难找到回复的方法。有人能给我指出正确的方向吗?grequests甚至可以返回xml响应吗?我应该只使用请求并自己执行线程吗? 这是文件代码

import grequests

urls = [
'http://www.heroku.com',
'http://python-tablib.org',
'http://httpbin.org',
'http://python-requests.org',
'http://kennethreitz.com'
]
rs = (grequests.get(u) for u in urls)
grequests.map(rs)

所以我的问题是,如何从映射请求到实际获取xml响应?提前感谢。

迭代
grequests.map的返回值。每个生成的项都是响应对象。您可以使用
content
属性获取内容

例如:

rs = (grequests.get(u) for u in urls)
for response in grequests.map(rs):
    print('{}: {}'.format(response.url, len(response.content)))

不幸的是,这只返回URL和结尾的代码。例如:
http://www.dictionaryapi.com/api/v1/references/thesaurus/xml/political?key=mykey'返回
:261`@user2758113,它不是代码。这是内容的长度。将
len(response.content)
替换为
response.content
。我使用了
len
,因为打印内容打印太多。