Skip to main content

Python Ghost Cursor

Python port of Xetera/ghost-cursor, for use with Pyppeteer and Playwright.

Generate realistic, human-like mouse movement data between coordinates or navigate between elements with Pyppeteer/Playwright like the definitely-not-robot you are.

Installation

pip install python_ghost_cursor

Usage

Generating movement data between 2 coordinates.

from python_ghost_cursor import path

start = {
    "x": 220,
    "y": 402,
}

end = {
    "x": 902,
    "y": 1032,
}

route = path(start, end)

 # [
 #   { "x": 100, "y": 100 },
 #   { "x": 108.75573501957051, "y": 102.83608396351725 },
 #   { "x": 117.54686481838543, "y": 106.20019239793275 },
 #   { "x": 126.3749821408895, "y": 110.08364505509256 },
 #   { "x": 135.24167973152743, "y": 114.47776168684264 }
 #   ... and so on
 # ]

Usage with Pyppeteer:

import asyncio
import pyppeteer
from python_ghost_cursor.pyppeteer import create_cursor

async def main(url):
  selector = "#sign-up button"
  browser = await pyppeteer.launch(headless=False)
  page = await browser.newPage()
  cursor = createCursor(page)
  await page.goto(url)
  await page.waitForSelector(selector)
  await cursor.click(selector)

asyncio.run(main())

Usage with Playwright (async):

import asyncio
from playwright.async_api import async_playwright
from python_ghost_cursor.playwright_async import create_cursor

async def main():
  async with async_playwright() as p:
    selector = "#sign-up button"
    browser = await p.chromium.launch(channel="chrome", headless=False)
    page = await browser.new_page()
    cursor = create_cursor(page)
    await page.goto(url)
    await page.wait_for_selector(selector)
    await cursor.click(selector)

asyncio.run(main())

Usage with Playwright (sync):

from playwright.sync_api import sync_playwright
from python_ghost_cursor.playwright_sync import create_cursor

def main():
  sync with sync_playwright() as p:
    selector = "#sign-up button"
    browser = p.chromium.launch(channel="chrome", headless=False)
    page = browser.new_page()
    cursor = create_cursor(page)
    page.goto(url)
    page.wait_for_selector(selector)
    cursor.click(selector)

main()

More info

The original repo gives a description of some of the cool features, along with a good explanation of how it works.

Release files for python-ghost-cursor 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-ghost-cursor 0.1.1
File Size Uploaded
python_ghost_cursor-0.1.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-ghost-cursor 0.1.1
File Interpreter ABI Platform
python_ghost_cursor-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size:31.5 kB

Release files / python_ghost_cursor-0.1.1.tar.gz

Download URL python_ghost_cursor-0.1.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e1015523b104ee995f9348205b9971bd863cdf81a2a06fe6186a7b4afed926f1
BLAKE2b-256 checksum
How to use checksums
05e87e22e3f738ef5c52bd5bfa0415da06baf632938690bda11469956f7bf17f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

Release files / python_ghost_cursor-0.1.1-py3-none-any.whl

Download URL python_ghost_cursor-0.1.1-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4fecf7ba52087b3c8b7c688f8587fa790ad91575c44b17e1b0db237c0c08849
BLAKE2b-256 checksum
How to use checksums
3f7e1920bc9e104c0fab556abd1ed5a8d536d4060b577c687f546e405ab3a584
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page