我正在尝试在Twisted中编写代理,记录在两个方向上通过它的所有流量。到目前为止,我可以捕获请求(GET,POST等)但不能捕获响应(无法查看网页的html)。
from twisted.web import proxy, http
from twisted.internet import reactor
from twisted.python import log
from twisted.protocols import basic
#log.startLogging(sys.stdout)
class MyProxy(proxy.Proxy):
def dataReceived(self, data):
# Modify the data here
print data
# perform the default functionality on modified data
return proxy.Proxy.dataReceived(self, data)
class ProxyFactory(http.HTTPFactory):
#protocol = proxy.Proxy
protocol=MyProxy
reactor.listenTCP(8080, ProxyFactory())
reactor.run()