1

I'm using bash to start a headless browser and would like the output meant for a file redirect and stored in a bash variable instead of file.

I can get the command below to work it outputs to a file:

chromium-browser --user-agent='Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1' --headless --proxy-server='direct://' --proxy-bypass-list=* --no-proxy-server --dump-dom http://google.com > webpage_data.txt

But I would like the output piped to a variable instead of a file

I tried the code below but it didn't work. I'm trying not to create a file for this output.

html=chromium-browser --user-agent='Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1' --headless --proxy-server='direct://' --proxy-bypass-list=* --no-proxy-server --dump-dom http://google.com 

Also this

chromium-browser --user-agent='Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1' --headless --proxy-server='direct://' --proxy-bypass-list=* --no-proxy-server --dump-dom http://google.com > html
Rick T
  • 3,349
  • 10
  • 54
  • 119

1 Answers1

0

Can you try this :

html=$(chromium-browser --user-agent='Mozilla/5.0 \(iPhone; CPU iPhone OS 12_2 like Mac OS X\) AppleWebKit/605.1.15 \(KHTML, like Gecko\) Version/12.1 Mobile/15E148 Safari/604.1' --headless --proxy-server='direct://' --proxy-bypass-list=* --no-proxy-server --dump-dom http://google.com)

You might need to escape a few characters inside the brackets. Though, I have already escaped ( and ) but in case it fails still.

Pacifist
  • 3,025
  • 2
  • 12
  • 20