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-web-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["status] 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.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.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_websites_scraper-0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 86463fa2abd505783e32ee8767918f27493e5b9850bdb9cd6151e33ade2e7404
MD5 bdaebaad23f07e0fe619bf400147d373
BLAKE2b-256 8185997321081826cc26fcbaca1b0f64af5d0a5ba33355ed52d8b1c9561f970c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_websites_scraper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c3b475fec64f6c9a36894eed76a3a9aace53a64a9d999d6fd289211a74d6284
MD5 48f1e4a6ca9aa78b0436ae1adfd9700c
BLAKE2b-256 7fc3ed30c885d7c918fb0a6f6e0a22502670f7ddd04fc251945930ab8ccfe9ae

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