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.3.tar.gz (4.3 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.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zr_web_scraper-0.1.3.tar.gz
  • Upload date:
  • Size: 4.3 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.3.tar.gz
Algorithm Hash digest
SHA256 bfe105a38c3ea82cacd21c82d7338817c66cce4aa5aaef05769bdfaa81e26e84
MD5 31523c4fc511133cb83e0cb93fe1b35e
BLAKE2b-256 04be23d83f44edaefc894520694a239404f0c8853b64925ffcbb0247cf16b23a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zr_web_scraper-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c86577b1cd1b0308b2588c32a206118f24a6c3bf6d613c3e9e58ec914c1ee651
MD5 2de69a97fcada28a6ec93e9df6867ea5
BLAKE2b-256 8db65c912ec4cebf26ee05a934613293babc72afd2d44ecfbf82cd778b828005

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