我将使用python http请求。我需要从httpbin.org/get获取请求,获取其内容,将其转换为xml格式并将其发回给httpbin.org/post。我还需要每分钟处理10-15个请求。我是否需要使用grequests(异步)或请求库?我试过的代码:
import grequests
urls = ['http://www.google.com/finance','http://finance.yahoo.com/','http://www.bloomberg.com/']
def def1(response,**kwargs):
print(response.url," is available...")
def def2(response,**kwargs):
print(response.url," content is: ",response.content)
def requestAsync(urls):
responses=[]
for u in urls:
get=grequests.get(u,hooks={'response':def1})
post=grequests.post("http://httpbin.org/post",hooks={'response':def2},data="some data")
responses.append(get)
responses.append(post)
return grequests.map(responses)
print(requestAsync(urls))
答案 0 :(得分:-1)
grequests绝对是实现设计的更好方式,但实现起来会更难。
您在使用代码时遇到的问题是什么?