A web scraping library that makes web-scraping easy
Project description
TITANScraper
v0.0.20
Description
A web scraping library that makes scraping easy. You can build complete web spiders and crawlers in a few lines of code
Installation
pip install titanscraper
Example
Assuming you have installed the library using pip as above,
the next thing to do is to import the module and create an instance of the TitanScraper class
from titanscraper import TitanScraper
scraper = TitanScraper()
Then you need to define rules. Rules are basically the instructions given to
the scraper to describe what to collect and name the data from a webpage. The most basic
structure of a rule is as follows:
{
"name": "item_name",
"selector": "some-css-selector",
}
The attribute name describes the name that will be given to specific data scraped from an
element that matches the selector in selector. Where selector is a valid CSS selector that actually references an HTML DOM element.
For example, assuming you want to collect the price of an item from an e-commerce website
where the price of the product is found within a span with class name price that is in an article object with class name product, you might want to do the following:
{
"name": "price",
"selector": "article.product > span.price",
}
Now you define your rules as a list as follows:
RULES = [
{
"name": "product-title",
"selector": "article.product > span.name"
},
{
"name": "product-price",
"selector": "article.product > span.price"
}
]
The next thing to do is to define your target webpages. This is just a list of URLS
# define a list of all the web pages you intend to scrap
target_pages = [
"https://www.target_website.fr/target_one",
"https://www.target_website.fr/target_two",
]
With that set, now you can scrap the data from all the pages in target_pages and parse data using the rules defined in RULES above as follows
# start the scraping of the target webpages.
data = scraper.scrap(target_pages, RULES)
The data returned by TitanScraper.scrap is a list of dictionaries
where the keys are the values from name in RULES and the values are
the data collected from the corresponding selector in the same rule.
Print your data to see what you have recieved as result.
print(data)
In normal circumstances (all pages scraped without error), the length of the list data
will be equal to the length of the list target_pages and the length of each item in
data will be the same as the number of rules in RULES.
Check python scripts in /examples directory to try real examples
Project details
Release history Release notifications | RSS feed
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 titanscraper-0.0.21.tar.gz.
File metadata
- Download URL: titanscraper-0.0.21.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21c05e9abf6e6b1b8e7f5c15661c6be3c133d1fde031df214174198e4a4240bf
|
|
| MD5 |
276e11e088f2c27554687ca80cf0c58d
|
|
| BLAKE2b-256 |
b061dbca159935314cf91d92cff91114ea99ad0967afe950d5e58729f5e1c84e
|
File details
Details for the file titanscraper-0.0.21-py3-none-any.whl.
File metadata
- Download URL: titanscraper-0.0.21-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08ef01d9d24f3249b9600c47a0602aecab377cc15c443c87de1c1f27bcb59a6c
|
|
| MD5 |
805316f8027ca30aade19f33eee2ffa8
|
|
| BLAKE2b-256 |
25dedb6033cad5114bbd1feb1e938ca9819dc14a257f3b46692ad30acfb57e7d
|