Skip to main content

Client library for https://github.com/snackbeard/web-scraper-api

Project description

Client Library

The client library makes it easy to access the API by providing a builder class.
Example:

    options = DriverOptions(
        user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
        options=['--headless', '--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage']
    )

    page_source = WebScraperBuilder(
                        url='https://my-domain.com',
                        api_key='c1f24ee0-1a77-4719-a33b-408069dfc15f')
                    .wait_for(seconds=5,
                          by=ApiInstructionIdentificatorType.CSS_SELECTOR,
                          wait_for=ApiInstructionElementType.ELEMENT_CLICKALBE,
                          element_id='button.sc-aXZVg.sc-lcIPJg.bjommA.jlhbaU.acceptAll',
                          ignore_error=True)
                    .click(ignore_error=True)
                    .wait_for(seconds=10,
                          by=ApiInstructionIdentificatorType.CSS_SELECTOR,
                          wait_for=ApiInstructionElementType.ELEMENT_PRESENCE,
                          element_id='div.category-event-items')
                    .scroll(block=ApiInstructionBlockType.END)
                    .get(page_url='https://www.page-to-scrape.com', options=options)

In the first .wait instruction a cookie dialog overlaps with the actual content we want to scrape. So to accept it we have to wait for the .acceptAll button to be clickable and then click it. Cookies won't appear again after accepting them once so if we scrape the site again an error would appear. So ignore_error is set to true in both instructions. Then we wait for an list to be present and scroll to the end of it to load all its content.

The following actions are currently supported

  • wait - simply waits
    • seconds seconds to wait
  • wait_for - wait for an element
    • seconds - seconds to wait
    • by - find it either by css selector or by element_id
    • wait_for - wait until the element is either present or clickable
    • element_id - id/selector of the element
    • ignore_error - if an element was not found ignore it and continue with the next instruction
  • find - find and element
    • by - find it either by css selector or by element id
    • element_id - id/selector of the element
    • ignore_error - ...
  • click - click an element after finding it or waiting for it
    • ignore_error - ...
  • scroll - scroll to an element after finding it or waiting for it
    • block - scroll to either end or start
    • _ignore_error - ...
  • get
    • page_url - webpage to scrape
    • content - page_source (html) or xhr (json)
    • xhr_name - document name (has to be provided if content is xhr)
    • options - chromedriver options

These instructions should be able to handle most use-cases

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

web_scraper_client-0.1.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

web_scraper_client-0.1.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file web_scraper_client-0.1.3.tar.gz.

File metadata

  • Download URL: web_scraper_client-0.1.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for web_scraper_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 166e7858153046440125a7de016ec7ec687e18b85f497dc1e8cdff0f7b7c8ce4
MD5 ad6183498413c692198eb9fd5f36377c
BLAKE2b-256 ec613ba4b6fc6aff1a437e28c7bf0e2ae49aa2683f2225bfc2a8455919ed696f

See more details on using hashes here.

File details

Details for the file web_scraper_client-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for web_scraper_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3f8c00fb4597a6ec2196110592e4b683d68dff628dde5c3a01f5131258928b1d
MD5 7f0020dd78030ab49a149067f599588d
BLAKE2b-256 1948541c4d6e39bdb817f5cc2b2ca26f979917952b185f738a3234163089bb5d

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