我正在使用browsermob代理和一个简单的脚本(下(效果非常慢。我想这是启动新服务器所需的时间。
如果是这种情况,是否可以在不同脚本执行之间启动服务器?
,或者如果不是这样,什么可以放慢我的脚本?
from browsermobproxy import Server
from selenium.webdriver.firefox.options import Options
from selenium import webdriver
import json
server = Server("/anaconda3/lib/python3.7/site-packages/browsermobproxy/browsermob-proxy-2.1.4/bin/browsermob-proxy")
server.start()
proxy = server.create_proxy()
print(1)
profile = webdriver.FirefoxProfile(profile_directory=r'./')
print(2)
profile.set_proxy(proxy.selenium_proxy())
print(4)
opts = Options()
opts.headless = True
driver = webdriver.Firefox(profile, executable_path=r'./geckodriver', options=opts)
print(5)
proxy.new_har()
driver.get("http://value.to")
proxy.har # returns a HAR JSON blob
#print(proxy.har)
print("analytics in value.to:")
for entry in proxy.har["log"]["entries"]:
if "google-analytics" in entry["request"]["url"]:
print(entry["request"]["url"])
print("nnn")
proxy.new_har()
driver.get("http://insightwhale.com")
proxy.har # returns a HAR JSON blob
#print(proxy.har)
print("analytics in insightwhale:")
for entry in proxy.har["log"]["entries"]:
if "google-analytics" in entry["request"]["url"]:
print(entry["request"]["url"])
print(json.dumps(proxy.har, indent=4, sort_keys=True))
file = open("____tmp.txt", "w")
file.write(json.dumps(proxy.har, indent=4, sort_keys=True))
file.close()
server.stop()
driver.quit()
哇,上帝知道为什么:" profile_directory = r'./'"正在放慢脚本。没有FirefoxProfile的此参数,一切都很快起作用。