nohup ./browsermob-proxy --port 9090 &
from browsermobproxy import Server
server = Server("/data/.workspace/selenium/browsermob-proxy-2.1.4/bin/browsermob-proxy", options={"port":9090})
server.start()
proxy = server.create_proxy()
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start() # 开启虚拟GUI
options = webdriver.ChromeOptions()
options.add_argument("--remote-debugging-port=9222")
options.add_argument("--no-sandbox")
options.add_argument('--allow-insecure-localhost')
options.add_argument('--ignore-ssl-errors=yes')
options.add_argument("--ignore-certificates-errors")
options.add_argument('--ignore-urlfetcher-cert-requests')
options.add_argument("--proxy-server={proxy_config}".format(proxy_config=proxy.proxy))
#options.add_argument("--headless")
options.add_argument('start-maximized')
#options.add_argument("--incognito")
options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors", "enable-automation", "enable-logging"])
prefs = {}
prefs["credentials_enable_service"] = False
prefs["profile.password_manager_enabled"] = False
options.add_experimental_option("prefs", prefs) ##关掉密码弹窗
capabilities = webdriver.DesiredCapabilities().CHROME
capabilities['acceptSslCerts'] = True
chrome = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=options, desired_capabilities=capabilities)
chrome.fullscreen_window()
proxy.new_har("jd", options={"captureHeaders": True, "captureContent": True, "captureBinaryContent": True})
chrome.get('https://www.jd.com/')
import time
time.sleep(15)
import json
fp = open("jdcom.har", "w")
# proxy.har # returns a HAR JSON blob
json.dump(proxy.har, fp)
fp.close()
proxy.close()
server.stop()
chrome.save_screenshot("chrome_jdcom.png")
chrome.quit()