3

I have a Linux server which can only be controlled via CLI. It doesn't have any browser installed, mainly because it is not needed and because unless it's lynx or a derivative, it is going to install x-server, which I don't want.

I know I can run Chrome and Firefox with the headless option, but it still requires to be installed.

Is there any way I can run selenium on that server without having to install one of the "main" browsers, or will I have to switch to another library (urllib, requests) if I want to programatically browse the web?

Hamperfait
  • 465
  • 1
  • 6
  • 18

1 Answers1

1

You can use phantomJS which is headless-selenium for your purpose.

Download phantomJS

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

Untar it

tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2

Move or copy it into the binary executable directory

cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/

import the selenium webdriver

from selenium import webdriver
wd = webdriver.PhantomJS()

connect to the website

wd.get("https://www.website-url.com")
Himanshu Poddar
  • 7,112
  • 10
  • 47
  • 93
  • 3
    phantomjs is no longer maintained ad deprecated within selenium – Corey Goldberg Dec 03 '18 at 15:33
  • 1
    your example never uses chrome_options it creates – Corey Goldberg Dec 03 '18 at 15:34
  • @CoreyGoldberg I know it has been deprecated but the OP wanted solution that could solve his problem for now. The solution is correct anyways. If the solution does not meet expectation in the long run does that mean you will downvote it?? In that case you should downvote all python 2 solution of problems. – Himanshu Poddar Dec 10 '18 at 18:10
  • it was deprecated long before the question was asked – Corey Goldberg Dec 10 '18 at 21:12
  • I have used PhantomJS, but as @CoreyGoldberg stated, it's been long deprecated and is unmantained. In the end I used a regular browser and installed X. Thanks anyway for the solution. – Hamperfait Dec 20 '18 at 07:11
  • Hamperfait I also have a solution using headless chrome. Reply if you need that. – Himanshu Poddar Dec 20 '18 at 07:26