Skip to main content

The WrapperXSelector is a Python-based tool that streamlines web scraping and data extraction tasks through the creation and utilization of wrappers.

Project description

WrapperXSelector(CroW)

PyPI Version Python Versions License

The WrapperXSelector is a Python-based tool that streamlines web scraping and data extraction tasks through the creation and utilization of wrappers. Leveraging Selenium for web automation and BeautifulSoup for HTML parsing, the project empowers users to effortlessly set up wrappers for tables and general data on web pages. With functions like setTableWrapper and setGeneralWrapper, users can define the structure of data extraction, while getWrapperData facilitates the retrieval of data based on these wrappers. Additionally, the project offers functionality for listing existing wrappers with listWrappers. Overall, the Web Wrapper Project serves as a versatile solution for simplifying web scraping workflows and enhancing data extraction efficiency in Python.

Table of Contents

Installation

Requirements

  • Python 3.x
  • Chrome browser (for Selenium)

Installation Steps

You can install the Web Wrapper Project using pip:

pip install WrapperXSelector

Usage

Setting up a Table Wrapper

To set up a table wrapper, use the setTableWrapper function. This function automates the process of creating a web scraping wrapper for a table on a specified web page.

Function Input:

  • URL (string): The URL of the web page containing the table you want to scrape.
  • Wrapper Name (string, optional): A custom name for the wrapper. If not provided, a unique name will be generated.
from web_wrapper_project import setTableWrapper

# Example: Setting up a table wrapper for "https://example.com" with a custom name
result = setTableWrapper("https://example.com", wrapper_name="my_table_wrapper")
print(result)

Function Output:

The setTableWrapper function returns a tuple with information about the operation:

  • Success Flag (bool): True if the operation was successful, False otherwise.
  • Wrapper Name (string): The name assigned to the wrapper, either custom or auto-generated.
  • Error Code (int or None): If unsuccessful, an error code indicating the nature of the failure. None if successful.
  • Error Type (string or None): The type of the raised exception (if any). None if successful.
  • Error Message (string or None): A descriptive error message (if any). None if successful.
# Example Output
# (True, 'my_table_wrapper_abc123.json', None, None, None)

Setting up a General Wrapper

To set up a general wrapper, use the setGeneralWrapper function. This function facilitates the creation of a web scraping wrapper for a general web page structure.

Function Input:

  • URL (string): The URL of the web page you want to scrape.
  • Wrapper Name (string, optional): A custom name for the wrapper. If not provided, a unique name will be generated.
  • Repeat (string, optional): Indicate whether to repeat the pattern. Options are 'yes' or 'no'. Default is 'no'.
from web_wrapper_project import setGeneralWrapper

# Example: Setting up a general wrapper for "https://example.com" with a custom name and repeat pattern
result = setGeneralWrapper("https://example.com", wrapper_name="my_general_wrapper", repeat="yes")
print(result)

Function Output:

The setGeneralWrapper function returns a tuple with information about the operation:

  • Success Flag (bool): True if the operation was successful, False otherwise.
  • Wrapper Name (string): The name assigned to the wrapper, either custom or auto-generated.
  • Error Code (int or None): If unsuccessful, an error code indicating the nature of the failure. None if successful.
  • Error Type (string or None): The type of the raised exception (if any). None if successful.
  • Error Message (string or None): A descriptive error message (if any). None if successful.
# Example Output
# (True, 'my_table_wrapper_abc123.json', None, None, None)

Getting Wrapper Data

To retrieve data from a previously set up wrapper, use the getWrapperData function. This function allows you to extract structured data from a web page based on the defined wrapper.

Function Input:

  • Wrapper Name (string): The name of the wrapper from which to retrieve data.
  • URL (string, optional): The URL of the web page. If not provided, the URL from the original wrapper setup will be used.
from web_wrapper_project import getWrapperData

# Example: Getting data from the wrapper named "my_table_wrapper"
result = getWrapperData("my_table_wrapper", url="https://example.com")
print(result)

Function Output:

The getWrapperData function returns a tuple with information about the operation:

  • Success Flag (bool): True if the operation was successful, False otherwise.
  • Data (list or string): If successful, the structured data extracted from the web page based on the wrapper. If unsuccessful, an error message describing the issue.
# Example Output
# (True, [['Column 1', 'Column 2'], ['Data 1', 'Data 2']])

# Example Output for Error
# (False, 'Permission denied: Unable to write to wrappers_5ece4797eaf5e')

Listing Wrappers

To retrieve a list of all available wrappers, use the listWrappers function. This function provides the names of all wrappers that have been set up in the system.

Function Input:

None

from web_wrapper_project import listWrappers

# Example: Listing all available wrappers
result = listWrappers()
print(result)

Function Output:

The listWrappers function returns a tuple with information about the operation:

  • Success Flag (bool): True if the operation was successful, False otherwise.
  • Wrappers (list or string): If successful, a list containing the names of all available wrappers. If unsuccessful, an error message describing the issue.
# Example Output
# (True, ['wrapper1.json', 'wrapper2.json'])

# Example Output for Error
# (False, 'Permission denied: Unable to read the wrappers')

Dependencies

Disclaimer

Intended for educational and legal use only. Users must comply with the terms of service of scraped websites and applicable laws and regulations.

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

WrapperXSelector-0.1.27.tar.gz (81.7 kB view details)

Uploaded Source

Built Distribution

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

WrapperXSelector-0.1.27-py3-none-any.whl (82.9 kB view details)

Uploaded Python 3

File details

Details for the file WrapperXSelector-0.1.27.tar.gz.

File metadata

  • Download URL: WrapperXSelector-0.1.27.tar.gz
  • Upload date:
  • Size: 81.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.1

File hashes

Hashes for WrapperXSelector-0.1.27.tar.gz
Algorithm Hash digest
SHA256 b6920a4f2c244c75a4fe5dd3ca7132daf89dd89009b86afa1eae8a5a818f675c
MD5 e2ab13b6786f1a2b0c6437a06b589d6c
BLAKE2b-256 d63869d3f34d1b8435347c4afbda09750111eecc90776247dd0dbcbf8d89e1cc

See more details on using hashes here.

File details

Details for the file WrapperXSelector-0.1.27-py3-none-any.whl.

File metadata

File hashes

Hashes for WrapperXSelector-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 81b2fb312abce158152edfcb7a36ae2276842970a319f7674a788d46d0a927b9
MD5 9ce0947add3d88a811bff73f88d3fe50
BLAKE2b-256 cce581d50596295f2142a06413531806383dd97e84876a07c88518a1c9d1cadc

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