Skip to main content

This is a test library

Project description

Python Version Contributions welcome License Build Status

Documentation Status PyPI - Downloads Stars

Some Changes A python library which can be used to extraxct data from files, pdfs, doc(x) files, as well as save data into these files. This library can be used to scrape and extract webpage data from websites as well.

Installation Requirements and Instructions

Python versions 3.8 or above should be installed. After that open your terminal: For Windows users:

pip install dputils

For Mac/Linux users:

pip3 install dputils

Files Module

Functions from dputils.files: for now, the files module has two functions:

  1. get_data:

    • To import, use statement:

      from dputils.files import get_data
      
    • Obtains data from files of any extension given as args(supports text files, binary files, pdf, doc for now, more coming!)

    • sample call:

      content = get_data(r"sample.docx")
      print(content)
      
    • Returns a string or binary data depending on the output arg

    • images will not be extracted

  2. save_data:

    • save_data can be used to write and save data into a file of valid extension.
    • sample call:
      from dputils.files import save_data
      
      pdfContent = save_data("sample.pdf", "Sample text to insert")
      print(pdfContent)
      
    • Returns True if file is successfully accessed and modified. Otherwise, False.

Scrape Module

Data extraction from a page

Here's a basic tutorial to help you get started with the scraper module.

  1. Import the required classes and functions:
from dputils.scrape import Scraper, Tag
  1. Initialize the Scraper class with the URL of the webpage you want to scrape:
url = "https://www.example.com"
scraper = Scraper(url)
  1. Define the tags you want to scrape using the Tag class:
title_tag = Tag(name='h1', cls='title', output='text')
price_tag = Tag(name='span', cls='price', output='text')
  1. Extract data from the page:
data = scraper.get_data_from_page(title=title_tag, price=price_tag)
print(data)

Extracting list of items from a page

For more advanced usage, such as extracting repeated data from lists of items on a page, you can use the following approach:

  1. Initialize the Scraper class:
url = "https://www.example.com/products"
scraper = Scraper(url)
  1. Define the tags for the target section and the items within that section: For repeated data extraction, you need to define Target and item and pass it to get_repeating_data_from_page() method.
    • target - defines the Tag() for area of the page containing the list of items.
    • items - defines the Tag() for repeated items within the target section. Like a product-card in product grid/list.
target_tag = Tag(name='div', cls='product-list')
item_tag = Tag(name='div', cls='product-item')
title_tag = Tag(name='h2', cls='product-title', output='text')
price_tag = Tag(name='span', cls='product-price', output='text')
link_tag = Tag(name='a', cls='product-link', output='href')
  1. Extract repeated data from the page:
products = scraper.get_repeating_data_from_page(
    target=target_tag,
    items=item_tag,
    title=title_tag,
    price=price_tag,
    link=link_tag
)
for product in products:
    print(product)

These functions can used on python versions 3.8 or greater.

References for more help: https://digipodium.github.io/dputils/

Contribution

if you want to contribute to this project and make it better, your help is very welcome.

  • Fork the project
  • Create your feature branch (git checkout -b feature/fooBar)
  • Commit your changes (git commit -am 'Add some fooBar')
  • Push to the branch (git push origin feature/fooBar)
  • Create a new Pull Request
  • Wait for your PR to be reviewed and merged
  • Star the project if you've found it useful
  • Share the project with your friends
  • Create an issue if you find a bug or want to request a new feature
  • Improve the project by refactoring the code
  • Review the PRs of other contributors
  • Suggest new features
  • Suggest new technologies to be used

Thank you for using dputils!

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

mymagic-0.0.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

mymagic-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file mymagic-0.0.2.tar.gz.

File metadata

  • Download URL: mymagic-0.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.9 Windows/11

File hashes

Hashes for mymagic-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d7e72947726c00032e9136e4bc2077b09034885b30e4b3fbc0e36466c42cbd7f
MD5 faf094a1c689cd7f2a1c91ebd30f8c10
BLAKE2b-256 e0b6dcb0b9e1002b0fc545ea87ca579eb8f09e19d3774757eba239504bd70468

See more details on using hashes here.

File details

Details for the file mymagic-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mymagic-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.9 Windows/11

File hashes

Hashes for mymagic-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b38a5dcaaa7293ff770f3ea9d13db54ab21da12c569427244e5fa86c800f01e
MD5 d8bebe0aa2354160e399bd224065c4fb
BLAKE2b-256 2dd23e8bbca9f93b4e127796374f0b306d861bb0d949721303dcfc4d24302489

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