A simple scrapper with structured JSON support
Project description
ScrapperJson
A simple automated scrapper with support for JSON structure of scrapping rules
Installation:
pip install scrapper-json-jawron
Usage:
from scrapper-json-jawron import Scrapper, get_rules_from_file
from dataclasses import dataclass
# example result dataclass
@dataclass
class Article:
url: str
title: str
content: str = ""
rules = get_rules_from_file("example.json")
# create templated scrapper
scr = Scrapper(rules, Article)
# scrap entity list
result = scr.scrap_list()
# scrap entity details
entity_rules = get_rules_from_file("example_entity.json")
for entity in result:
entity_result = scr.scrap_entity(entity_rules, entity)
JSON structure
Main options
- type: Defines the type of scrapping data, can be either
xmlorhtml - pagination: Defines if the scrapping should perform pagination using a templated url from rules file,
default: false - pagination_limit: Defines the number of pages to scrape,
default: 100 - url: Defines the url of XML feed or HTML page that will be scrapped
- root: Defines the root element at which scrapping begins
- entry: Defines the particular entries elements which will be scrapped to separate objects
- elements: Defines the scrapped properties of an entity
Elements options
- selector: Defines the CSS or XML selector for the element
- item_type: Defines the type of item, can be either
singleorlist,default: single - attribute: Defines the attribute of element which will be scrapped, if scrapping text use
text, else use the name of the attribute. You can also scrape an element as an object to use in nested properties.default: text - prefix: Defines the prefix which is added to the result property
- suffix: Defines the suffix which is added to the result property
- remove: Defines the text which is to be removed from the result property
- replace: Defines the text which is to be replaced from the result property
Example HTML
{
"type": "html",
"url": "https://www.technewsworld.com/archive",
"root": {
"selector": "div.category-article-list",
"attribute": "element"
},
"entry": {
"selector": "div.search-item",
"attribute": "element",
"item_type": "list"
},
"elements": {
"title": {
"selector": "div.search-txt a h2",
"attribute": "text"
},
"url": {
"selector": "div.search-txt a",
"attribute": "href"
}
}
}
Example XML
{
"type": "xml",
"url": "https://www.cijeurope.com/rss/posts/en.xml",
"root": "channel",
"entry": "item",
"elements": {
"title": {
"selector": "title",
"attribute": "text"
},
"url": {
"selector": "link",
"attribute": "text"
}
}
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change or add.
Plans for future
- Pagination handling ✅
- Network error handling and retries ✅
- More export options (file etc.) ✅
- Login handling, session management
- Export to database
- Rule-based data transformation and cleaning
- Support for asynchronous requests
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scrapper_json_jawron-0.1.2.tar.gz.
File metadata
- Download URL: scrapper_json_jawron-0.1.2.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bd164bd58aa07dba8e7e42eb70c282a21e827a61d0e012406cd9b12b1e9e141
|
|
| MD5 |
fba7abf14dddb90777cb2682f9a660c3
|
|
| BLAKE2b-256 |
1bd868a27205da125c3c8cf7dfae2a1820f585c15b2a9d7ffa5861e01e18e8eb
|
Provenance
The following attestation bundles were made for scrapper_json_jawron-0.1.2.tar.gz:
Publisher:
python-publish.yml on TheTasak/ScrapperJson
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scrapper_json_jawron-0.1.2.tar.gz -
Subject digest:
7bd164bd58aa07dba8e7e42eb70c282a21e827a61d0e012406cd9b12b1e9e141 - Sigstore transparency entry: 584506667
- Sigstore integration time:
-
Permalink:
TheTasak/ScrapperJson@6196e8e92051ac514afebce384a65c68fab7a8e4 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/TheTasak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6196e8e92051ac514afebce384a65c68fab7a8e4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file scrapper_json_jawron-0.1.2-py3-none-any.whl.
File metadata
- Download URL: scrapper_json_jawron-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18414fa9095b12f483a6c7d0a82e9ed47fa21f6a5406f10170dd4d81403db28a
|
|
| MD5 |
a927dc648d9926ee1db388dc5554fe1f
|
|
| BLAKE2b-256 |
aec94befc2f5d31c4857d530b0e31859eb823df4110cde746b9b27be2030a2db
|
Provenance
The following attestation bundles were made for scrapper_json_jawron-0.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on TheTasak/ScrapperJson
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scrapper_json_jawron-0.1.2-py3-none-any.whl -
Subject digest:
18414fa9095b12f483a6c7d0a82e9ed47fa21f6a5406f10170dd4d81403db28a - Sigstore transparency entry: 584506670
- Sigstore integration time:
-
Permalink:
TheTasak/ScrapperJson@6196e8e92051ac514afebce384a65c68fab7a8e4 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/TheTasak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6196e8e92051ac514afebce384a65c68fab7a8e4 -
Trigger Event:
release
-
Statement type: