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?

3
  • if dynamic page use selenium + browser else beautifulsoup. Commented Dec 1, 2018 at 9:53
  • You can run selenium in a docker container Commented Dec 1, 2018 at 17:13
  • I believe phantomJS doesn't require X, but the others do. Commented Dec 1, 2018 at 22:45

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

6 Comments

phantomjs is no longer maintained ad deprecated within selenium
your example never uses chrome_options it creates
@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.
it was deprecated long before the question was asked
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.