Python wrapper for PhantomJS
Project description
PhantomJS wrapper in Python
Pre requisites
- phantomjs:
phantomjs
command line tool. - 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
Release history Release notifications | RSS feed
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.3.0.tar.gz
(6.5 kB
view hashes)
Built Distribution
Close
Hashes for phantomjs-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c837b4202223d953887f3dd20a062c32c7df26a704ecd11af6a757f43c0bcb7d |
|
MD5 | 5563d8a4eee33cacaf5d94499b7fc5dc |
|
BLAKE2b-256 | baedb220ec1dd57b71e74e94f94623c3379f64ce0ba8b5d9d18a6be25487d351 |