Skip to main content

A web scraping library for selenium and beautifulsoup

Project description

Here is a sample code for a good scraper logic with some validation logic. It helps to build a good scraper with validation steps and repeat logic.

Installation

pip install pyselenscrapr

Usage

from pyselenscraper.ScrapingBot import ScrapingBot, TakeScreenshotModes
from pyselenscraper.ScrapingLogic import ScrapingLogic
from pyselenscraper.ScrapingStep import ScrapingStep, ScrapingStepInterval, ScrapingStepErrorHandling

...
# Initialize selenium driver
driver = webdriver.Remote("http://localhost:4444/wd/hub", options=ff_options)
...

robot = ScrapingBot(driver, take_screenshots_mode=TakeScreenshotModes.Always)

try:

   search_command = "wikipedia matrix movies"

   robot.add_step(ScrapingStep("Check if there is a visible 'Accept all' or 'decline all' button",
                               lambda l: l.get_best_element("//button//div[contains(text(), 'All')]").click(),
                               interval=ScrapingStepInterval.BeforeAnyStep,
                               error_handling=ScrapingStepErrorHandling.Ignore,
                               can_execute=lambda l: l.current_url and "google" in l.current_url and l.is_visible("//button//div[contains(text(), 'All')]"),
                               was_executed=lambda l: not l.is_visible("//button//div[contains(text(), 'All')]"),),
                  step_group="default")

   ...
   # Your scraper Logic here
   ...

   finished_success = robot.run()

   if finished_success:
       print("The robot finished successfully")
   else:
       print("The robot did not finish successfully")

except Exception as e:
   log.error(e)
finally:
   driver.quit()

Documentation

The documentation is available at https://pyselenscrapr.readthedocs.io/.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

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

pyselenscrapr-0.0.81.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

pyselenscrapr-0.0.81-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file pyselenscrapr-0.0.81.tar.gz.

File metadata

  • Download URL: pyselenscrapr-0.0.81.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for pyselenscrapr-0.0.81.tar.gz
Algorithm Hash digest
SHA256 0b94dccb614fc0652d2f37b5f055ee64d7dda7e216754ead4ae38bf17528bcd4
MD5 a2be10159bf8df646113dea17cd93bcd
BLAKE2b-256 0b35d723e0bffd3314626ecec4f3ba90c0e598df406e6788d60b425a94653471

See more details on using hashes here.

File details

Details for the file pyselenscrapr-0.0.81-py3-none-any.whl.

File metadata

File hashes

Hashes for pyselenscrapr-0.0.81-py3-none-any.whl
Algorithm Hash digest
SHA256 3faace5e72a66bf22b429878c69835924b8fa712606516f7bad0fe8261f5b5c1
MD5 126c4b35e358b22a7b9c217c53a384b9
BLAKE2b-256 a9a53eabc40696eaf595fb5da082854c08e1ea7bf72551ca09bae6565462e276

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page