Skip to main content

A useful package for web scraping with Selenium

Project description

Py-Easy-Scrape

Description

A useful package for web scraping with Selenium.

This package provides useful wrapping of some of the more cumbersome aspects of using Selenium directly, such as initializing the WebDriver, scrolling, and handling elements.

Also, it simplifies some common tasks in web scraper bots, such as asking the user to manually input some data when necessary and checking if some file exists in the user's computer.

Moreover, it kind of does the same with Logging: Py Easy Scrape comes with built-in logging, which can be a significant advantage for quickly deploying, debugging, and monitoring your web scraping project!

Installation

pip install py-easy-scrape

Requirements

  • Python 3.7 or higher
  • Selenium, along with GeckoDriver (Firefox)

Usage

Py-Easy-Scrape has a built-in logging system that, so far, needs a directory for all the logs that are going to be generated. Hence, in your project directory, create a new directory called 'logs':

mkdir logs

Then, import the package:

import pyeasyscrape as pes

Get WebDriver

driver = pes.get_webdriver(headless=True)

This will return a headless instance of webdriver.Firefox (GeckoDriver).

Get Element

element = pes.get_element(driver, value="element_xpath")

This will return the web element found using the specified driver and value. By default, this function uses 'XPATH' as the method of searching. However, you can change this by providing 'ID' or 'LINK_TEXT' as the 'by' argument.

Please be aware that the method of searching ('XPATH', 'ID', or 'LINK_TEXT') highly depends on the webpage structure. Therefore, it is essential to inspect the webpage beforehand.

Also, please remember to replace "element_xpath" with the actual Xpath, ID, or link text of the element you want to find.

Scroll to Element

pes.scroll_to(driver, element)

This will use JavaScript to scroll the view of the given webdriver to the specified web element.

Ask for Data

required_data = ("username", "password")
file_name_no_extension = "user_credentials"
pes.ask_for_data(required_data, file_name_no_extension)

This will return a dictionary containing the collected data and will create a JSON configuration (.conf) file.

Check File

pes.check_file("path_to_file")

This will return either True or False based on file existence

Please note that the above code snippets are basic examples of how to use those functions. Depending on the exact specifications of your use case, additional setup may be necessary (e.g. logging into a website before trying to scroll to an element).

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

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

py-easy-scrape-0.1.6.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

py_easy_scrape-0.1.6.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file py-easy-scrape-0.1.6.1.tar.gz.

File metadata

  • Download URL: py-easy-scrape-0.1.6.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.6.0 pkginfo/1.9.6 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.7.16

File hashes

Hashes for py-easy-scrape-0.1.6.1.tar.gz
Algorithm Hash digest
SHA256 c6f69721ec8e73497170571d7afcef9f3e757077936cdfdca4b2ad3ace09c192
MD5 b70d68fc5cd43a69d986f2ca2c7d653f
BLAKE2b-256 67e494ec2c2dfc681dfc166bc20a0723d9a88d40812f38a264ba9a9c7d85f1e7

See more details on using hashes here.

File details

Details for the file py_easy_scrape-0.1.6.1-py3-none-any.whl.

File metadata

  • Download URL: py_easy_scrape-0.1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.6.0 pkginfo/1.9.6 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.7.16

File hashes

Hashes for py_easy_scrape-0.1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7def119fd11f5744c5badb66bd440a19e5bdcbd34c9a59204ba09fc734b9037
MD5 31fcb6fe5782391abfe5a9dd2636382f
BLAKE2b-256 4a27825e251b725298bb9261d83c1441c1084cf07f075b828834036a5619793c

See more details on using hashes here.

Supported by

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