Write scraping rules, get dictionaries.
scrapedict is a Python module designed to simplify the process of writing web scraping code. The goal is to make scrapers easy to adapt and maintain, with straightforward and readable code.
Features
- The rules dictionary is straightforward and easy to read
- Once you define the rules for one item you can extract multiple items
- You get ✨dictionaries✨ of the data you want
Installation
$ pip install scrapedict
Usage
import scrapedict as sd
from urllib.request import urlopen
# Fetch the content from the Urban Dictionary page for "larping"
url = "https://www.urbandictionary.com/define.php?term=larping"
content = urlopen(url).read().decode()
# Define the fields to be extracted
fields = {
"word": sd.text(".word"),
"meaning": sd.text(".meaning"),
"example": sd.text(".example"),
}
# Extract the data using scrapedict
item = sd.extract(fields, content)
# The result is a dictionary with the word, its meaning, and an example usage.
# Here, we perform a couple of assertions to demonstrate the expected structure and content.
assert isinstance(item, dict)
assert item["word"] == "Larping"
The orange site example
import scrapedict as sd
from urllib.request import urlopen
# Fetch the content from the Hacker News homepage
url = "https://news.ycombinator.com/"
content = urlopen(url).read().decode()
# Define the fields to extract: title and URL for each news item
fields = {
"title": sd.text(".titleline a"),
"url": sd.attr(".titleline a", "href"),
}
# Use scrapedict to extract all news items as a list of dictionaries
items = sd.extract_all(".athing", fields, content)
# The result is a list of dictionaries, each containing the title and URL of a news item.
# Here, we assert that 30 items are extracted, which is the typical number of news items on the Hacker News homepage.
assert len(items) == 30
Development
Dependencies are managed with Poetry.
Testing is done with Tox.
Metadata
Release files for scrapedict 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scrapedict-0.3.1.tar.gz | 3.6 kB | Without provenance | Details for scrapedict-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scrapedict-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for scrapedict-0.3.1-py3-none-any.whl |
Total release size: 6.5 kB
Release files / scrapedict-0.3.1.tar.gz
| Download URL | scrapedict-0.3.1.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
189436e69e0ea57370e43fcece6ed39832b511959aae343ce000a4ba82b8e011
|
|
BLAKE2b-256 checksum How to use checksums |
21f6414b5fc402bbff008ffa34adefbef9b39440f7e56ebab810f819cb596210
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.2
|
Release files / scrapedict-0.3.1-py3-none-any.whl
| Download URL | scrapedict-0.3.1-py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36364ddbdcbfe9d8b53ca9115c0c2797e938947ee8c2abbb82a6f8395b584cf6
|
|
BLAKE2b-256 checksum How to use checksums |
0bc4c8e31e1194cef7f5a6c0d44a9d629d0c045d6e27a9edbb4c95a95a88b77a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.2
|
Security for scrapedict 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.