Skip to main content

Python wrapper for PhantomJS

Project description

Build Status

PhantomJS wrapper in Python

Pre requisites

  1. phantomjs: phantomjs command line tool.
  2. Python 3

Install

pip install phantomjs

Usage

Using with a custom phantomjs script:

from phantomjs import Phantom

phantom = Phantom()

conf = {
    'url': 'http://example.com/',   # Mandatory field
}
output = phantom.download_page(conf, js_path='/my/phantomjs/script/path')

In your phantomjs script, you can take the url as:

var system = require('system');
var json = JSON.parse(system.args[1]);
var url = json.url;

Using the default phantomjs script provided with this package:

from phantomjs import Phantom

phantom = Phantom()

conf = {
    'url': 'http://example.com/',   # Mandatory field
    'output_type': 'html',          # json for json
    'min_wait': 1000,               # 1 second
    'max_wait': 30000,              # 30 seconds
    'selector': '',                 # CSS selector if there's any
    'resource_timeout': 3000,       # 3 seconds
    'headers': {
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.72 Safari/537.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
        "Sec-Fetch-Mode": "navigate",
        'Sec-Fetch-Site': 'same-origin',
        'Upgrade-Insecure-Requests': '1',
    },
    'cookies': [
        {'name': '_Country', 'value': 'US', 'domain': '.google.com',},
        {'name': '_Currency', 'value': 'USD', 'domain': '.google.com',},
    ],
    'functions': [
        'function(){window.location.replace("http://icanhazip.com/");}',
    ],
}


output = phantom.download_page(conf)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phantomjs-1.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phantomjs-1.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file phantomjs-1.2.0.tar.gz.

File metadata

  • Download URL: phantomjs-1.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for phantomjs-1.2.0.tar.gz
Algorithm Hash digest
SHA256 dc403b7e339c6bc5a07a3df872b11c562135e011ed95f8d93c3777daeee4c631
MD5 b7b82df877c695023a532ac797dbed59
BLAKE2b-256 e41b645f89b254202020735fb46315b3426b20764ea5cffeb4dd6c8bf8fcc5ab

See more details on using hashes here.

File details

Details for the file phantomjs-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: phantomjs-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2

File hashes

Hashes for phantomjs-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9e4b60ecfdca88f7f3f0a860664daa56f6610abcd93ae6954fe9f6c84827b7b
MD5 3bcce25b12bed2a4aa6937b3308bcaf8
BLAKE2b-256 0d4c537e1ecc01bbc2c7900b87bf333de1f868f47ec83ae692722aedebb9da19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page