Sesame HTTP: Installation of PhantomJS and sesame httpphantomjs
PhantomJS is an unbounded WebKit browser engine that can be programmed with scripts. It supports a variety of native Web standards: DOM operations, CSS selectors, JSON, Canvas, and SVG.
Selenium supports PhantomJS, so that no browser will pop up during running. In addition, PhantomJS is highly efficient and supports various parameter configurations for ease of use. Next, let's take a look at the installation process of PhantomJS.
1. Related Links
- Http://phantomjs.org
- Official documents: http://phantomjs.org/quick-start.html
- : Http://phantomjs.org/download.html
- API Description: http://phantomjs.org/api/command-line.html
2. Download PhantomJS
We need to download the corresponding installation package on the official website. PhantomJS supports multiple operating systems, such as Windows, Linux, Mac, and FreeBSD. we can select the corresponding platform and download the installation package.
After the download is complete, configure the path of the PhantomJS executable file to the environment variable. Environment, we need to put it directly in the path where the environment variable is configured or configure its path to the environment variable. For example, you can copy it directly to the Scripts folder of Python, or add the bin directory where it is located to the environment variable.
For configuration of environment variables in Windows, see section 1.1. For configuration of Linux and Mac environment variables, see section 1.2.3, the key is to configure the path of the executable file of PhantomJS to the environment variable.
After the configuration is successful, you can test it in the command line and enter:
phantomjs
If you can access the command line of PhantomJS, it proves that the configuration is complete, as shown in 1.
Figure 1 Console
3. Verify Installation
In Selenium, we only need to switch Chrome to PhantomJS:
from selenium import webdriverbrowser = webdriver.PhantomJS()browser.get('https://www.baidu.com')print(browser.current_url)
After running the command, we will not find any browser pop-up, but PhantomJS is actually running. Here we visited Baidu and printed the current URL.
The console output is as follows:
https://www.baidu.com/
In this way, we have completed the PhantomJS configuration, which can be used later to capture some pages.
Here we will introduce the connection methods of three mainstream browsers corresponding to Selenium. We will further explore the connection methods of Selenium and various browsers.