Developers: Code a Phantom

Definitions:

Script:

The code that will be executed by node.js in the cloud, using Puppeteers, Buster libraries, and more. 

Catalog:

The list of scripts you can execute in our cloud. For example, Phantombuster provides a public catalog of scripts.

Phantom:

A Phantom is a Headless Chrome that runs a script in the cloud.

Org:

When you sign up for an account on Phantombuster, an org is automatically created for you. It represents the Phantoms you'll use and the scripts you'll code. Your org contains your catalog of Phantoms that you can share or not. e.g., Phantombuster's catalog is public.

Branch:

Your catalog displays the "master" branch. You can create as many branches as you want. Each script can be shared and executed. Each branch is composed of 

  1. - Staging
  2. - Release 

Setup:

The multiple section setup for configuring a Phantom. Usually composed of two steps: 

  1. The input you'll need from the user, written in JSON
  2. The launch settings, such as the frequency, and notifications

 

Create and execute a Phantom

This walkthrough will guide you from the creation of a script to its public release into the catalog of your org. Before you begin, make sure you've enabled developer mode on your account.

 

Create a script

From the 'My Phantoms' page, go to the 'Developer' section:

    • Menu (top right)
    • Developer
Screenshot_2019-10-07_at_19.26.09.png

Set up a new script:

    • Create script
    • Set a name (no extension needed)
Screenshot_2019-10-07_at_19.26.18.png

Attach the script to the “master” branch 

    • Three little dots
    • Branch into...
    • Set branch name (“master”)
Screenshot_2019-10-07_at_19.26.43.png

Code a Phantom

    • Go to the Phantom's page
    • Three little dots
    • Make public
    • Again, three little dots
    • Edit code
    • Code (see sample code)
    • Save and close the editor
Screenshot_2019-10-07_at_19.26.55.pngScreenshot_2019-10-21_at_15.23.45.png
// Phantombuster configuration {
"phantombuster command: nodejs"
"phantombuster package: 5"
"phantombuster flags: save-folder"

const Buster = require("phantombuster")
const buster = new Buster()
const puppeteer = require('puppeteer')
// }

;(async () => {
const browser = await puppeteer.launch({
args: ["--no-sandbox"] // this is needed to run Puppeteer in a Phantombuster container
})
const page = await browser.newPage()
await page.goto('https://news.ycombinator.com')
await page.screenshot({path: 'screenshot.png'})
await buster.setResultObject({pageTitle: await page.title()})
await page.close()
await browser.close()
process.exit()
})()

 

Test Phantom in staging mode

    • Use this Phantom
    • Go through the Setup and save
    • Launch
Screenshot_2019-10-07_at_19.27.25.pngScreenshot_2019-10-07_at_19.27.29.pngScreenshot_2019-10-07_at_19.27.44.pngScreenshot_2019-10-07_at_19.27.42.png

Debug the code

    • Three little dots
    • Toggle console
Screenshot_2019-10-07_at_19.27.51.pngScreenshot_2019-10-07_at_19.27.59.png

Set the Phantom as public

    • Menu
    • Developer
    • Select the “master” branch
    • Select the script to publish
    • Release
Screenshot_2019-10-07_at_19.29.05.png

Share your Phantom

    • Select the Release option
    • Share your script link
    • ...or the link of your catalog (only public scripts will be available)
Screenshot_2019-10-07_at_19.30.27.pngScreenshot_2019-10-08_at_11.23.00.png

 

SDK

If you don't want to use the built-in script editor, you can use our SDK. See this guide for more details.

 

Support

If you have any questions about the creation of scripts, please tell us using the support button :)

Was this article helpful?
4 out of 7 found this helpful