Hello Dear All,
My question is based on Ubuntu CLI
environment.
I am running 20.04. "server" edition
What I would like to do is to get HAR
response of a website in terminal.
Is there a command line solution that simulates what we are doing on Chrome,
*open chrome on terminal,
*head over to url,
*click on any link given on that website,
*open developer options and copy the json formatted HAR values etc..
When I check google, answers of this question is almost 8 years old. So I want to believe that there are better solutions instead of Selenium. Anyway,
What I have tried so far:
System update & installation of selenium requirements:
sudo apt-get update
sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
# Install Chrome.
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
# Update our system
sudo apt-get -y update
# Install Chrome
sudo apt-get -y install google-chrome-stable
# Install Chromedriver
wget -N https://chromedriver.storage.googleapis.com/95.0.4638.54/chromedriver_linux64.zip -P ~/
unzip ~/chromedriver_linux64.zip -d ~/
# Remove zip file
rm ~/chromedriver_linux64.zip
# Move driver to bin location
sudo mv -f ~/chromedriver /usr/local/bin/chromedriver
# Give it rights
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver
# Install Selenium
pip install selenium
Now :
pip freeze | grep "selenium"
returns:
selenium==4.16.0
har.py
from browsermobproxy import Server
from selenium import webdriver
import json
server = Server("/usr/local/bin/chromedriver")
server.start()
proxy = server.create_proxy()
profile = webdriver.FirefoxProfile()
profile.set_proxy(self.proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("$$$_target_url_here$$$", options={'captureHeaders': True})
driver.get("$$$_target_url_here$$$")
result = json.dumps(proxy.har, ensure_ascii=False)
print result
proxy.stop()
driver.quit()
when I give it a go in ubuntu server, it returns error:
python3 har.py
File "har.py", line 13
print result
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(result)?
Does it work only on desktop versions of ubuntu or which step is wrong in this study?
Thank you
Boris