我需要一个 python http 客户端,它可以重用连接并支持在流进来时使用它。它将用于解析 xml 流,sax 样式。
我想出了一个解决方案,但我不确定它是不是最好的(有很多方法可以在 python 中编写 http 客户端)
class Downloader():
def __init__(self, host):
self.conn = httplib.HTTPConnection(host)
def get(self, url):
self.conn.request("GET", url)
resp = self.conn.getresponse()
while True:
data = resp.read(10)
if not data:
break
yield data
谢谢各位!