我刚开始使用browsermob-proxy实用工具。下面是我的代码,它在我的本地实例上运行得很好,但是当我在我的ec2实例(使用headless browser)上尝试它时,它给了我一个错误:
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任何帮助都将不胜感激!
发布于 2020-02-20 02:36:47
我通过一些改变让它工作起来了。
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 optionshttps://stackoverflow.com/questions/59061251
复制相似问题