Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

titanscraper-0.0.20.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

titanscraper-0.0.20-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file titanscraper-0.0.20.tar.gz.

File metadata

  • Download URL: titanscraper-0.0.20.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

Hashes for titanscraper-0.0.20.tar.gz
Algorithm Hash digest
SHA256 fbdc58e6fae5573753e445d4689a54f2019d19ad5eb0fe880eec8a2e096dd530
MD5 10738e50f6296828783619e5efa1eb66
BLAKE2b-256 80e58e9fc517d7de380b568945736904b5307bd049dea0e5ba0508645f6bfe10

See more details on using hashes here.

File details

Details for the file titanscraper-0.0.20-py3-none-any.whl.

File metadata

  • Download URL: titanscraper-0.0.20-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

Hashes for titanscraper-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 c5174048d44c917d9074b843e87b50cfdc5cb41b2638839e2337b284d8b96380
MD5 dd03efdfa3ca0d5c5535ab3a4735fc94
BLAKE2b-256 0624e8d8d14378e61f5669ef90585b20b4cd87d2d5eeef79a5acb47204cf5589

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