Skip to content

A very simple Python web scraping module for Reichelt Elektronik

License

Notifications You must be signed in to change notification settings

jkreucher/ReicheltAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web scraping module for Reichelt Elektronik

Copyright 2021 Jannik Kreucher

Table of Contents

Introduction

ReicheltAPI is a very simple Python libaray for pulling data from the rather popular german distributor Reichelt Elektronik. This is achived by scraping the Reichelt website with BeautifulSoup4. The goal of this project is to build a python module for generating BOMs and price estimates within KiCad.

Stand Alone

If you just want to get information about a Reichelt part you can use the stand-alone functionality of the module. The usage is pretty simple:

python3 reichelt.py "<ReicheltArtikelNr>" <attribute>

Dont forget the parentheses around the part name when using spaces. The attribute can be one of the following:

Attribute Function
all everything as json for you to mess around
part shows parsed part number, should be the same as "PartName"
name Reichelt product name
link link to the item
datasheet link to the pdf datasheet
1 price of one item
10 price per item when buying 10
100 price when ordering 100
1000 price when ordering 1000

Examples:

~$ python3 reichelt.py "Z84C00-06MHZ" name  # returns name of item
Z80 Microprozessor, 6 MHz, DIP40
~$ python3 reichelt.py "Z84C00-06MHZ" 1  # return unit price in Euro
7.25

Python Quick Start

A very simple script to get started:

import reichelt
import json

part = "74HC 00"

# create API object
api = reichelt.Reichelt()
result = api.search_part(part)

# print info
print(json.dumps(result, indent=4))

# download datasheet
api.get_datasheet(result["datasheet"], part+".pdf")

Here the variable result contains the following:

{
    "part": "74HC 00",
    "name": "4-fach, 2 Eingangs-NAND-Gatter,  2 ... 6 V, DIL-14",
    "link": "https://www.reichelt.de/de/de/4-fach-[...]",
    "1": 0.26,
    "10": null,
    "100": null,
    "1000": null,
    "datasheet": "https://www.reichelt.de/index.html?[...].pdf",
    "Allgemeines": {
        "Familie": "74HC",
        "Modell": "NAND-Gate",
        "Typ": "2 Eingänge",
        "Ausführung": "4-Elemente",
        "Bauform": "DIP-14"
    },
    "Sonstiges": {
        "Temperaturbereich": "-40 ... +85 °C"
    },
    "Elektrische Werte": {
        "Versorgungsspannung": "2,0 ... 6,0 VDC",
        "Eingangsspannung Vi": "0 ... 6,0 VDC",
        "Leistung": "500 mW",
        "Eingangsspannung ViH": "4,2 VDC",
        "Eingangsspannung ViL": "0,5 VDC"
    },
    "Herstellerangaben": {
        "Verpackungsgewicht": "0.001 kg",
        "RoHS": "konform",
        "EAN / GTIN": "9900000031190"
    },
    "categories": [
        "Startseite",
        "Bauelemente",
        "Bauelemente, aktiv",
        "ICs & Controller",
        "ICs digital",
        "Logik-ICs"
    ]
}

Creating the object

To start scraping data, the object needs to be constructed:

import reichelt
foo = reichelt.Reichelt()

Note that the file reichelt.py needs to be in the same directory

Searching with a string

The function get_search_results(keyword) starts a search on the Reichelt homepage like you would in your browser. But it returns a dict with the most important information.

result = foo.get_search_results("Z80")
[
	{
        "part": "Z84C00-10MHZ",
        "name": "Z80 Microprozessor, 10 MHz, DIP40",
        "link": "https://www.reichelt.de/de/de/z80-microprozessor-10-mhz-dip40-z84c00-10mhz-p31823.html[...]",
        "1": 7.12,
        "10": null,
        "100": null,
        "1000": null
    },
    {
        "part": "Z84C30-06MHZ",
        "name": "Z80 MICRPROZESSOR DIL-28",
        "link": "https://www.reichelt.de/de/de/z80-micrprozessor-dil-28-z84c30-06mhz-p23034.html[...]",
        "1": 6.67,
        "10": null,
        "100": null,
        "1000": null
    }
...

The function returns a array of the items found by the keyword or string. Note that only items on the first page are parsed. The key 1 is the price for this specific item. The keys 10, 100 and 1000 show the discounted price for the respective order volume. Null means there is no discount obviously.

Getting more data

To get even more information about a item the function get_search_results(keyword) can be utilized. It requires a link to a specific item and returns more information about the product.

product = foo.get_part_information("https://www.reichelt.de/z80-microprozessor-10-mhz-dip40-z84c00-10mhz-p31823.html?&trstct=pos_2&nbc=1")

Or if you want to use the link provided by get_search_results above directly:

product = foo.get_part_information(result[0]["link"])
{
    "datasheet": "https://www.reichelt.de/index.html?ACTION=7&LA=3&OPEN=0&INDEX=0&FILENAME=A300%2FZ84C00%23ZIL.pdf",
    "Allgemeines": {
        "Modell": "Microprozessor",
        "Typ": "CPU",
        "Ausführung": "4 Kanäle",
        "Bauform": "PDIP-40"
    },
    "Besonderheiten": {
        "CPU Takt": "10 MHz"
    },
    "Herstellerangaben": {
        "Hersteller": "ZILOG",
        "Artikelnummer des Herstellers": "Z84C0010PEG",
        "Verpackungsgewicht": "0.007 kg",
        "EAN / GTIN": "9900000318239"
    },
    "categories": [
        "Startseite",
        "Bauelemente",
        "Bauelemente, aktiv",
        "ICs & Controller",
        "ICs digital",
        "8-Bit Microcontroller"
    ]
}

But I want it in one line

search_part(part) combines the two and is meant for getting data about an item when the Reichelt part number is known. The part number is passed as a string. Note that the part number must be exact!

product = reichelt.Reichelt().search_part("74HC 00")

Downloading Datasheets

This module allows you to download the datasheet from Reichelt as well. Since the link to the datasheet is parsed by get_part_information it is very easy to implement:

foo.get_datasheet(product["datasheet"], "foo.pdf")

Now the datasheet for the product above is saved in "foo.pdf".

About

A very simple Python web scraping module for Reichelt Elektronik

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages