Skip to main content

Web scraper using aiohttp for efficient scraping of multiple URLs with ease

Project description

About

Scrape main content on multiple websites using Python in parallel.

You still need to use proxy if the access to the website is blocked. Read "More Parameters" section.

Dependency

How to use

pip install py-websites-scraper

Quick usage:

import asyncio
from py_websites_scraper import scrape_urls

urls = ["https://news.ycombinator.com", "https://example.com"]
data = asyncio.run(scrape_urls(urls, max_concurrency=5))
for item in data:
    if item["success"] is True:
        print(item["url"], item.get("title"), item.get("content"))
    else:
        print("Failed fetching this URL: " + item["url"])

Available key on the response:

url
success # True/False
title   # only available when it's successful
content # only available when it's successful
error   # only available when it's failed

You can always check the success value if it's true, before fetching the title or content.

More parameters

You can add any parameters for aiohttp to perform the request like headers, proxy, and more. Please check aiohttp documentation for reference.

Example:

urls = []
results = await scrape_urls(
    urls,
    proxy="YOUR_PROXY_INFO",
    headers={"User-Agent": "USER_AGENT_INFO"},
)

Limitation

  • Gated content
  • Dynamic generated content

How the test the package locally for Dev

Install in editable mode:

pip install -e .

Run any file that importing this package

python test_local.py

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_websites_scraper-0.1.2.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

py_websites_scraper-0.1.2.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file py_websites_scraper-0.1.2.1.tar.gz.

File metadata

  • Download URL: py_websites_scraper-0.1.2.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for py_websites_scraper-0.1.2.1.tar.gz
Algorithm Hash digest
SHA256 da02adb055217d3a60c6b467786229a48d8e705aac25c1af37a3be3ff7e0374d
MD5 b834d6f21e6d0890b0060c15ab3701cd
BLAKE2b-256 9e7c2f2fb4b8e06f2a43e31a96940056a7c346d0cec4792bbc11ca837495123d

See more details on using hashes here.

File details

Details for the file py_websites_scraper-0.1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_websites_scraper-0.1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb0ac0cf12cb7c252b7133d32b22cf4c23dad85083e9172b0d2e1098b5d0c86b
MD5 0fba4e49370e493b43f63a19067364b2
BLAKE2b-256 93d05689849cd30278aad52bfc0539ee1de8be17d1a9d86b0eedd127341e45de

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