Skip to main content

ScrapPyJS Class

The ScrapPyJS class provides functionality for web scraping using Selenium were you can Scrap data via running JS script directly from python.

Constructor

__init__(script=None, browser=None, show=False, debug=False, strict=False)

The constructor initializes a ScrapPyJS object with the following parameters:

  • script (optional): The JavaScript code to be executed by the web browser.

  • browser (optional): An existing instance of a Selenium WebDriver. If not provided, a new instance will be created using Chrome.

  • show (optional): Boolean value indicating whether to show the browser window. Default is False.

  • debug (optional): Boolean value indicating whether to enable debug mode. Default is False.

  • strict (optional): Boolean value indicating whether to enable strict mode. Default is False.

Methods

ScrapPyJS.setup_browser()

This method sets up the web browser instance. It creates a new instance of a Chrome WebDriver with the specified options based on the constructor parameters.

ScrapPyJS.set_script(script)

This method sets the JavaScript code to be executed by the web browser.

  • script: The JavaScript code to be executed.

ScrapPyJS.scrap(url, wait=False, wait_for=None, wait_target=None, wait_time=10)

This method performs web scraping on the specified URL.

  • url: The URL to scrape.

  • wait (optional): Boolean value indicating whether to wait for an element to be present on the page before scraping. Default is False.

  • wait_for (optional): The method to use for locating the element to wait for. Possible values are 'class', 'id', 'name', 'tag', 'link', 'part_link', 'css', or 'xp'. Default is None.

  • wait_target (optional): The target value to locate the element to wait for. Default is None.

  • wait_time (optional): The maximum time (in seconds) to wait for the element to be present. Default is 10.

Returns the result of executing the JavaScript code on the web page.

ScrapPyJS.end()

This method terminates the web browser instance if it exists.

How to Use

  1. Import the ScrapPyJS:

    from ScrapPy import ScrapPy
    
  2. Create an instance of the ScrapPyJS class:

    scrappy = ScrapPyJS()
    
  3. Set JS script as string to return a value from the website

    scrappy.set_script("return 'ScrapPy scrapping!'")
    
  4. Use the scrap method to scrape a webpage:

    result = scrappy.scrap(url, wait=True, wait_for='id', wait_target='elementId')
    
  5. Retrieve the result of the scraping operation:

    print(result)
    
  6. Terminate the web browser instance when finished:

    scrappy.end()
    

Please note that you will need to have the necessary Selenium and WebDriver dependencies installed to use this code.

Download files

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

Source Distribution

ScrapPyJS-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

ScrapPyJS-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file ScrapPyJS-1.0.0.tar.gz.

File metadata

  • Download URL: ScrapPyJS-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for ScrapPyJS-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f6a0439c25a86eeccd9ff53d199e73c240806139f861a7dd05a57d27d554b504
MD5 564b926fe1953e39c2e98978b03b96ff
BLAKE2b-256 cbb07d2224eff60c96ef2b0fd82f5be1c6d54e9667878a8f25e6cef008cfc3f0

See more details on using hashes here.

File details

Details for the file ScrapPyJS-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ScrapPyJS-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for ScrapPyJS-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50d41d6ced8a744c730b574a0e45673f3c0dadf387b0861a779108fb190a71de
MD5 470745462edd919d2b1974735612055a
BLAKE2b-256 72ba4064cadaa72eac2a3ac00125d6e0c0f6a0eac282799b9ab20ad9aa7dcb66

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 Sentry Error logging StatusPage Status page