我正在尝试使用库 scotch 记录浏览器发送的 HTTP GET/POST 请求。
我正在使用他们的示例代码:http ://darcs.idyll.org/~t/projects/scotch/doc/recipes.html#id2
import scotch.proxy
app = scotch.proxy.ProxyApp()
import scotch.recorder
recorder = scotch.recorder.Recorder(app, verbosity=1)
try:
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
server_address = ('', 8000)
httpd = WSGIServer(server_address, WSGIRequestHandler)
httpd.set_app(app)
while 1:
httpd.handle_request()
finally:
from cPickle import dump
outfp = open('recording.pickle', 'w')
dump(recorder.record_holder, outfp)
outfp.close()
print 'saved %d records' % (len(recorder.record_holder))
所以我运行了上面的代码,转到谷歌浏览器,并访问了一些网站,看看是否会被记录下来。
但是,我看不到代码应该如何终止。似乎 httpd.handle_request() 中必须有一个错误才能终止代码。
我尝试了代码的变体,其中删除了 try 和 finally 语法,并更改了 while 条件以使循环运行 30 秒。但是,这似乎也一直在运行。
关于如何使它工作的任何想法?我也愿意使用其他可用的 python 库来做我想做的事情:记录我的浏览器的 GET/POST 请求,包括登录,并在 python 中重播。
谢谢。