Skip to main content

A simple Web scraper package

Project description

Web Scraper Package

This package allows you to scrape Web search results using Python.

Necessary Commands

To test be on directory zr_web_scraper

pytest test/

Web Scraper

This package allows you to scrape Web search results using Python. It’s useful for retrieving information from search results for automated data collection or analysis tasks. The GoogleScraper class in this package is designed to fetch and parse search results, returning structured data for further processing.

Table of Contents

Installation

Clone the Repository

Clone this repository to your local machine:

git clone https://github.com/yourusername/zr_web_scraper.git
cd zr_web_scraper

Install Required Packages

Use pip to install the necessary packages:

pip install -r requirements.txt

Usage

Example Code

To scrape Web search results, use the GoogleScraper class. Here’s a simple example:

from zr_google_scraper.scraper import GoogleScraper

# Initialize the scraper
scraper = GoogleScraper()

# Perform a search and print the results
results = scraper.scrape("OpenAI ChatGPT")
for result in results:
    print(f"Title: {result['title']}")
    print(f"Link: {result['link']}")
    print(f"Content: {result['content']}
")

This code performs a search for "OpenAI ChatGPT" and prints out the title, link, and content snippet for each result.

Project Structure

zr_web_scraper/
├── zr_google_scraper/
│   ├── __init__.py
│   ├── scraper.py            # Contains the main GoogleScraper class
├── tests/
│   ├── test_zr_google_scraper.py    # Unit tests for GoogleScraper
├── setup.py
├── requirements.txt
├── README.md
  • zr_google_scraper/: Contains the Google scraping logic.
  • tests/: Unit tests for validating scraper functionality.
  • setup.py: Script for packaging the module.
  • requirements.txt: Lists dependencies required for this project.
  • README.md: Documentation for the project.

Testing

To run the tests, navigate to the root directory (zr_web_scraper) and use pytest:

cd zr_web_scraper
pytest tests/

This command will execute all tests in tests/test_zr_google_scraper.py and provide output on the test status.

Test Coverage

  • No Results Test: Ensures that the scraper correctly identifies when there are no search results.
  • Success Test: Validates that the scraper accurately parses titles, links, and content from search results.
  • Failure Test: Simulates a network error to confirm the scraper handles exceptions gracefully.

Dependencies

Install the following dependencies as listed in requirements.txt:

  • requests: For handling HTTP requests.
  • beautifulsoup4: For parsing HTML content.

Notes

  • Legal Considerations: Scraping Google results might violate Google’s terms of service. Use this tool responsibly and check Google’s policies regarding automated data collection.
  • Rate Limiting: Google might block IPs that perform automated searches frequently. Consider adding delays between requests if running multiple searches in succession.

License

This project is licensed under the MIT License.

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

zr_web_scraper-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

zr_web_scraper-0.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file zr_web_scraper-0.1.2.tar.gz.

File metadata

  • Download URL: zr_web_scraper-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for zr_web_scraper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 636809faa345a1642e9dbfca18cb82bdd802f84f1727ecf30168f2cdcb911dd5
MD5 7053ed095f5844e32dfac0a700cca122
BLAKE2b-256 b3ec4f407eed3838fdd66a7fdef32b07fcdf50b839d78f8a7bbcd6c94182dd77

See more details on using hashes here.

File details

Details for the file zr_web_scraper-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: zr_web_scraper-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for zr_web_scraper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eefb70cb61bf1e83caf00c9bc0182d56bfd811ba5935e0383c9cd85193a05bf1
MD5 ffb912bf5ed0f3ff0634c794fbc2c58e
BLAKE2b-256 c751616131919cb34da753f6add14545789a64f6cc089f8bd2e1a94b539e46bd

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