我为此使用代理
from selenium import webdriverfrom browsermobproxy import Serverserver = Server(environment.b_mob_proxy_path)server.start()proxy = server.create_proxy()service_args = ["--proxy-server=%s" % proxy.proxy]driver = webdriver.PhantomJS(service_args=service_args)proxy.new_har()driver.get('url_to_open')print proxy.har # this is the archive# for example:all_requests = [entry['request']['url'] for entry in proxy.har['log']['entries']]“ har”(http存档格式)还有许多有关请求和响应的其他信息,这对我非常有用
在Linux上安装:
pip install browsermob-proxy



