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?
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.