October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Use PhantomJS with Python (and What to Use Instead)

PhantomJS used JavaScript and GhostDriver; Python controlled it through Selenium. Here’s how the legacy setup worked and a supported headless Chrome migration example.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Historically, Python used Selenium’s WebDriver interface to control the separate PhantomJS executable; PhantomJS itself ran JavaScript, not Python. That integration is now legacy: the PhantomJS project says development is suspended, its GitHub repository has been read-only since May 30, 2023, and its 2.1 release dates to January 23, 2016. For new Python automation, use Selenium with a maintained browser such as Chrome.

How the historical Python–PhantomJS integration worked

PhantomJS was a headless browser based on QtWebKit, with a JavaScript API for tasks such as page automation, screenshots, testing, and network monitoring. Python did not call that page API directly. Instead, Python code sent browser commands through Selenium WebDriver to the PhantomJS executable, using GhostDriver, which was embedded in PhantomJS.

The PhantomJS command-line reference applies to version 2.1.1. It documents starting the WebDriver endpoint with --webdriver; the default address is 127.0.0.1:8910. Separately, PhantomJS scripts are JavaScript files run from the command line as phantomjs [options] somescript.js. The project’s API documentation shows JavaScript calls such as page.open(url, callback), whose callback receives a status of success or fail. See the PhantomJS project homepage, command-line reference, and page.open API reference.

The project states, “Important: PhantomJS development is suspended until further notice.” PhantomJS 2.1 was released on January 23, 2016, and the GitHub repository was archived on May 30, 2023. Those dates matter when deciding whether to retain a legacy integration or build a new one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Running an existing PhantomJS script

If you are maintaining an old script, run its JavaScript file with the PhantomJS executable. This is not Python code:

phantomjs somescript.js

Options may be placed between the executable and the script name. For example, the documented WebDriver mode is started with --webdriver; consult the 2.1.1 command-line reference for its options. The Python side of an old integration would connect through Selenium to that WebDriver service. Do not assume a legacy call such as webdriver.PhantomJS() works with a current Selenium release: the available project documentation does not establish compatibility between contemporary Selenium versions and PhantomJS.

Use Selenium with headless Chrome for new Python code

Selenium’s current Python documentation supports browser automation with maintained browser options including Chrome, Edge, Firefox, Safari, WebKitGTK, and WPEWebKit. Choose the browser engine that matches the users or environment your automation needs to represent. For a local Chrome example, Selenium documents creating a Chrome WebDriver and Chrome documents the --headless=new argument:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    print(driver.title)
finally:
    driver.quit()

Install Selenium in the Python environment used to run the script, and install Chrome. Selenium Manager generally handles driver setup when webdriver.Chrome() is created. If you install and manage ChromeDriver yourself, the official Chrome guidance says its major version must match the browser’s major version. See Selenium documentation and ChromeDriver version selection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the execution model that fits the job

  • Local browser automation: use Selenium with the browser your application must support, then run the script on a machine with that browser installed.
  • Remote or grid execution: Selenium also supports running sessions through a remote Grid; this is an optional deployment model, not a requirement for a local script.
  • HTTP retrieval rather than browser behavior: if the task only needs a straightforward HTTP response and parsing, a browser-automation stack may be unnecessary. Use browser automation when JavaScript execution, browser rendering, or UI interaction is part of the requirement.

Or skip the browser setup

If your goal is a website screenshot rather than interactive browser testing, ScreenshotNeo can return an image or PDF from one GET request. Its API can accept and remove cookie-consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. ScreenshotNeo also provides an MCP server with screenshot, page-info, and PDF tools for AI agents.

For example, this cURL request saves a screenshot of example.com as WebP. Replace YOUR_API_KEY with your API key. See the API documentation for output and capture options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots. Sign up for free and get 1,000 screenshots a month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

PhantomJS is not found

The command-line executable is missing or is not on the shell’s PATH. Install or locate the legacy executable for the environment where the script runs, then verify the shell can invoke phantomjs. Because the project is suspended, do not treat this as a maintained setup for new deployments.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Python PhantomJS WebDriver call fails

A legacy Selenium binding may not be compatible with the Selenium version installed. The cited PhantomJS documentation does not establish a working pairing with current Selenium, so do not try to fix this by assuming an old constructor remains supported. For new work, migrate the WebDriver session to a supported browser; if preserving the old system is unavoidable, verify the exact Selenium and PhantomJS versions in that environment.

The WebDriver connection is refused

Check that the PhantomJS process started in WebDriver mode and that Python is connecting to the same host and port. The documented default endpoint is 127.0.0.1:8910; a custom --webdriver port requires the client to use that port too.

Chrome starts but the script cannot find its driver

Allow Selenium Manager to resolve the driver when creating webdriver.Chrome(), or check your manual driver installation. When managing it yourself, ensure ChromeDriver and Chrome have matching major versions as specified by Chrome’s version-selection guidance.

A page looks different in headless mode

Headless execution is still browser automation, but it may not match the assumptions of an old QtWebKit-based PhantomJS run. Confirm the chosen browser engine is appropriate for the target, and debug the page in that same browser before attributing a difference to Python or Selenium.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.