Python Can';无法连接到Browsermob代理ProxyServerError
我不熟悉使用browsermob代理实用工具。下面是我的代码,它在本地实例上运行得非常好,但当我在ec2实例上尝试它(使用headless browser)时,会出现一个错误:Python Can';无法连接到Browsermob代理ProxyServerError,python,selenium-webdriver,browsermob-proxy,browsermob,Python,Selenium Webdriver,Browsermob Proxy,Browsermob,我不熟悉使用browsermob代理实用工具。下面是我的代码,它在本地实例上运行得非常好,但当我在ec2实例上尝试它(使用headless browser)时,会出现一个错误: raise ProxyServerError("Can't connect to Browsermob-Proxy") browsermobproxy.exceptions.ProxyServerError: Can't connect to Browsermob-Proxy 我的本地实例设置和ec2实例设置之间的唯
raise ProxyServerError("Can't connect to Browsermob-Proxy")
browsermobproxy.exceptions.ProxyServerError: Can't connect to Browsermob-Proxy
我的本地实例设置和ec2实例设置之间的唯一区别是,在ec2上,它在无头浏览器上运行
代码段:
def start_proxy_server():
for proc in psutil.process_iter():
# check whether the process name matches
if proc.name() == "browsermob-proxy":
proc.kill()
dict = {'port': 7190}
server = Server(path="path_to_browswermob/browsermob-proxy-2.1.4/bin/browsermob-proxy", options=dict)
server.start()
time.sleep(1)
proxy = server.create_proxy()
time.sleep(1)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy)) #Configure chrome options
driver = webdriver.Chrome('path_to_chromedriver/chromedriver',options=chrome_options)
options = Options()
options.headless = True
driver.get("www.google.com")
return driver, proxy
任何帮助都将不胜感激 我对它进行了一些修改
def start_proxy_server():
for proc in psutil.process_iter():
# check whether the process name matches
if proc.name() == "browsermob-proxy":
proc.kill()
dict = {'port': 8080}
server = Server(path="path_to_browswermob/browsermob-proxy-2.1.4/bin/browsermob-proxy", options=dict)
server.start()
time.sleep(1)
proxy = server.create_proxy()
time.sleep(1)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy)) #Configure chrome options
在我看来,使用无头不应该是一个问题。(面临同样的问题)您的ec2上安装了java吗?是的,我的ec2@George312上安装了java