how do I import browsermobproxy in python?

4,344 views
Skip to first unread message

Simon

unread,
Jan 29, 2013, 6:29:26 PM1/29/13
to BrowserMob Proxy
I'm having trouble with:
from browsermobproxy import Server

Please see below:

[sgalkov@zpub-web-203 browsermob-proxy-2.0-beta-7]$ python display.py
Google
[sgalkov@zpub-web-203 browsermob-proxy-2.0-beta-7]$ cat display.py
from pyvirtualdisplay import Display
from selenium import webdriver
#from browsermobproxy import Server

#server = Server("/home/sgalkov/browsermob/browsermob-proxy-2.0-beta-7/
bin/browsermob-proxy")
#server.start()
#proxy = server.create_proxy()
#proxy.new_har("google")

#initialize HIDDEN display
display = Display(visible=0, size=(800, 600))
display.start()

#initialize webdriver
browser = webdriver.Firefox()

browser.get('http://www.google.com')
print browser.title

#proxy.har
browser.quit() #important, or else loaded browser will remain running
as a bg proc!
display.stop()
#server.stop()
[sgalkov@zpub-web-203 browsermob-proxy-2.0-beta-7]$ pwd
/home/sgalkov/browsermob/browsermob-proxy-2.0-beta-7

#here i'm uncommenting the browsermobproxy Server import
[sgalkov@zpub-web-203 browsermob-proxy-2.0-beta-7]$ vi display.py
[sgalkov@zpub-web-203 browsermob-proxy-2.0-beta-7]$ python display.py
Traceback (most recent call last):
File "display.py", line 3, in <module>
from browsermobproxy import Server
ImportError: No module named browsermobproxy
[sgalkov@zpub-web-203 browsermob-proxy-2.0-beta-7]$

after I uncomment:
from browsermobproxy import Server

the script won't run because it cannot find that library although that
library is right there in that folder and the bin is there, I just
dont understand how it should include it and ive searched everywhere
online. It must be something really trivial that I don't understand
because i can't find anybody else complain about it. As you can see,
the other two libraries on top of the file are easily found by the
script because they were installed via easy_install/pip/yum but
browsermobproxy was simply gunzipped so i believe it isn't included in
the global path.

I downloaded and gunzipped this file:
http://dl.dropbox.com/u/1995643/browsermob-proxy/browsermob-proxy-2.0-beta-7-bin.zip
as instructed on http://opensource.webmetrics.com/browsermob-proxy/

any help would be greatly appreciated, I have been trying to get this
working for a number of days now.

My linux box is CentOS6.2 and I'm trying to run headless selenium tests

Sindhu Rajan

unread,
Feb 14, 2013, 2:48:59 PM2/14/13
to browserm...@googlegroups.com

Hi Simon,

Could you please let me know how you were able to fix this?

Thanks,
Sindhu

Carlos Torres

unread,
Feb 14, 2013, 2:59:17 PM2/14/13
to browserm...@googlegroups.com
Hi Simon,

It seems you have the binary for the proxy, but you still need to install the python library to interact with the browsermobproxy.

Try this:

pip install browsermob-proxy

and then re-run your script.

Here's the official page for the library:



--Carlos Torres


--
 
---
You received this message because you are subscribed to the Google Groups "BrowserMob Proxy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to browsermob-pro...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Simon

unread,
Feb 20, 2013, 5:26:22 PM2/20/13
to browserm...@googlegroups.com
@Sindhu here is my latest script:

from pyvirtualdisplay import Display
from selenium import webdriver

import sys
sys.path.append("/home/sgalkov/browsermob-proxy-py/")
from browsermobproxy import Server

server = Server("/home/sgalkov/browsermob/browsermobproxy/bin/browsermob-proxy")
server.start()
proxy = server.create_proxy()

#initialize HIDDEN display
display = Display(visible=0, size=(800, 600))
display.start()

proxy.new_har("w3")

#initialize webdriver
profile  = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
browser = webdriver.Firefox(firefox_profile=profile)
#browser = webdriver.Firefox()

browser.get('http://www.w3.org')
print browser.title

#print dir(proxy.har)
print proxy.har()
print proxy.webdriver_proxy()
print server.port
print server.url
#print browser.page_source

browser.quit() #important, or else loaded browser will remain running as a bg proc!
display.stop()
server.stop()


if you do "import sys" and then append, it will include those python libraries.

@Carlos, yes I was confused as to how this works. I got a little further but still could not get the har file.. it was always being returned empty. I've given up on the python
implementation and switched over to java.. It was also difficult to get Java working on a headless box so switched over to my windows 7 machine for now. Later I plan on moving the setup
to a linux box with GUI.

On Tuesday, January 29, 2013 3:29:26 PM UTC-8, Simon wrote:

Bianca Pirte

unread,
Feb 26, 2013, 2:04:34 PM2/26/13
to browserm...@googlegroups.com, carlos....@upr.edu
I am using python on win7
I have installed browsermob-proxy (pip install browsermob-proxy) and I get

from browsermobproxy.server import Server
ImportError: No module named server


if using:  from browsermobproxy.server import Server   (this is from eclipse suggested imports for Server)

i am using selenium 2.27
browsermob 0.2.0


tried
 from browsermobproxy import Server 
still does not work

any suggestions?

thanks

Simon

unread,
Feb 26, 2013, 2:48:05 PM2/26/13
to browserm...@googlegroups.com, carlos....@upr.edu
post your full code somewhere so we can see

Bianca Pirte

unread,
Mar 4, 2013, 3:43:28 AM3/4/13
to browserm...@googlegroups.com, carlos....@upr.edu
st.JPG

Simon

unread,
Mar 4, 2013, 2:27:42 PM3/4/13
to browserm...@googlegroups.com, carlos....@upr.edu
Try to add the bmp python folder like this:

import sys
sys.path.append("/path-to/browsermob-proxy-py/")

and then try importing Server

Lindsay Ogden

unread,
Jun 9, 2014, 7:10:27 PM6/9/14
to browserm...@googlegroups.com, carlos....@upr.edu
Simon, Bianca, I'm having the same problem, this is my code currently:

********************
import sys
sys.path.append('/Applications/BrowserMobProxy/browsermob-proxy-py')
from browsermobproxy import Server
server = Server('/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/browsermobproxy')
server.start()
proxy = server.create_proxy()
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("google")
driver.get('http://google.com')
#print driver.title
proxy.new_har
server.stop()
driver.quit()
********************

Python responds with:
Traceback (most recent call last):
  File "scratch.py", line 3, in <module>
    from browsermobproxy import Server
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/browsermob_proxy-0.6.0-py3.2.egg/browsermobproxy/__init__.py", line 3, in <module>

ImportError: No module named server

I have installed the library with pip, and placed the git package at /Applications/BrowserMobProxy/browsermob-proxy-py

If I append that second line with /browsermobproxy, so it reads:
sys.path.append('/Applications/BrowserMobProxy/browsermob-proxy-py/browsermobproxy')

Then Python responds with:
Traceback (most recent call last):
  File "scratch.py", line 3, in <module>
    from browsermobproxy import Server
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/browsermob_proxy-0.6.0-py3.2.egg/browsermobproxy/__init__.py", line 3, in <module>
    from server import Server
  File "/Applications/BrowserMobProxy/browsermob-proxy-py/browsermobproxy/server.py", line 7, in <module>
    from client import Client
  File "/Applications/BrowserMobProxy/browsermob-proxy-py/browsermobproxy/client.py", line 2, in <module>
    from urllib import urlencode
ImportError: cannot import name urlencode

Thanks in advance,
-Lindsay

Anastasiia Panchenko

unread,
Apr 28, 2015, 11:03:52 AM4/28/15
to browserm...@googlegroups.com, carlos....@upr.edu
Hi Lindsay Ogden,

I had the same error either. It disappears when I installed browsermob-proxy with setup.py:


$ python setup.py install

But it would be nice to know what is the difference...

понедельник, 9 июня 2014 г., 19:10:27 UTC-4 пользователь Lindsay Ogden написал:
Reply all
Reply to author
Forward
0 new messages