我正在使用libmproxy来捕获 http 流量。我想在代理运行时使用网络驱动程序加载网页。代理代码运行良好,但我无法启动该页面。我假设脚本在 m.run() 处陷入循环。如何在代理运行时移至 Web 驱动程序代码?
import unittest
import sys
from libmproxy import proxy, dump, cmdline
from libmproxy.version import VERSION
from optparse import OptionParser
from selenium import webdriver
class Test(unittest.TestCase):
def setUp(self):
parser = OptionParser(
usage = "%prog [options] [filter]",
version="%%prog %s"%VERSION,
)
cmdline.common_options(parser)
parser.add_option(
"--keepserving",
action="store_true", dest="keepserving", default=False,
help="Continue serving after client playback or file read. We exit by default."
)
options, args = parser.parse_args()
if options.quiet:
options.verbose = 0
proxyconfig = proxy.process_proxy_options(parser, options)
if options.no_server:
server = proxy.DummyServer(proxyconfig)
else:
try:
server = proxy.ProxyServer(proxyconfig, options.port, options.addr)
except proxy.ProxyServerError, v:
print >> sys.stderr, "mitmdump:", v.args[0]
sys.exit(1)
try:
dumpopts = dump.Options(**cmdline.get_common_options(options))
except cmdline.OptionException, v:
parser.error(v.message)
dumpopts.keepserving = options.keepserving
if args:
filt = " ".join(args)
else:
filt = None
try:
PROXY_HOST = "localhost"
PROXY_PORT = 8080
#driver.get("http://msn.com")
#f = open('/Users/cnave/Documents/capture/dump.txt', 'w')
#sys.stdout('/Users/cnave/Documents/capture/dump.txt', 'w')
#open('/Users/cnave/Documents/capture/dump.txt', 'w')
m = dump.DumpMaster(server, dumpopts, filt)
m.run()
#sys.stdout('/Users/cnave/Documents/capture/dump')
fp = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", PROXY_PORT)
fp.set_preference("network.proxy.no_proxies_on", "") # set this value as desired
driver = webdriver.Firefox(firefox_profile=fp)
driver.get('http://google.com')
except dump.DumpError, e:
print >> sys.stderr, "mitmdump:", e
sys.exit(1)
except KeyboardInterrupt:
pass