Skip to main content

Python implementation of Xetera/ghost-cursor

Project description

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.

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

python_ghost_cursor-0.1.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

python_ghost_cursor-0.1.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file python_ghost_cursor-0.1.0.tar.gz.

File metadata

  • Download URL: python_ghost_cursor-0.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for python_ghost_cursor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c539d40cf1d036575f562c1693df2a78521eb2b4415984ca8f1082983c95d472
MD5 f02dd6c8980e2367c3c0e1d951bb9855
BLAKE2b-256 98c59e780a1718b223e11df8289a50e6f2b06e833bffd6e55b614a15ebab0678

See more details on using hashes here.

File details

Details for the file python_ghost_cursor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_ghost_cursor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for python_ghost_cursor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a6e035b228573f6370e6fa78c9f4527a4ec52b859f3854c15f747fc276e0e90
MD5 aa1b890219a57fec5b00dd28f142dc3a
BLAKE2b-256 389e39b993a03ba92f3dd4e473aa1d62e40d4fbb83915ea63a2c5aab359e2fc2

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