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
Release history Release notifications | RSS feed
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.3.tar.gz
(14.9 kB
view hashes)
Built Distribution
Close
Hashes for pyselenscrapr-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f7c60b36541604df44c546c7f1d31220d77fdcdf97c0e69b95599bc67ced222 |
|
MD5 | 5f935a645a3087973e52c66939999968 |
|
BLAKE2b-256 | 59e81ba92d136258945f7346d6fac4e6604f5a2fb8c4563b34b96b54d40795af |