Skip to content

Examples

Marcelo Perrella edited this page Oct 7, 2019 · 2 revisions

Table of Contents

Choosing the Scraper

The Scraper allows for different types of entities to be scraped by using the correct scraper. You can read more about it here.

const { Item, Recipe, MaterialGroup } = require('bdo-scraper')

// Using ES7 async/await syntax.
async () => {
    // Returns the data for the item with id 9213.
    const itemData = await Item(9213)

    // Returns the data for the recipe with id 122.
    const recipeData = await Recipe(122)

    // Returns the data for the material group with id 1.
    const MaterialGroupData = await MaterialGroup(1)
}

// Using promises.
Item(9213).then(data => console.log(data))
Recipe(122).then(data => console.log(data))
MaterialGroup(1).then(data => console.log(data))

Changing the Data Language

By default, the Scraper will always return the data in english. However, this can be changed by passing a lang flag to the second parameter. This can be achieved easily by using the built-in enum.

// Don't forget to import the LANGS enumerator.
const { Recipe, Enums } = require('bdo-scraper')

async () => {
    const data = await Item(122, Enums.LANGS.pt)
}

Full Item vs Skipping Extra Calls

Skipping Recipe Data

By default, the Scraper will request all available data, even if that means making extra requests. If the data is not necessary, then pass a false boolean to the third parameter.

const { Item, Enums } = require('bdo-scraper')
async () => {
    // The third parameter should return false.
    const data = await Item(9213, Enums.LANGS.en, false)
    console.log(data)
}

If succesful, this would return an object like:

{
    "id":            9213,
    "name":          "Beer",
    "grade":         1,
    "icon":          "/items/new_icon/03_etc/07_productmaterial/00009213.png",
    "type":          "Special Items",
    "weight":        "0.10 LT",
    "description":   "A mild alcoholic drink brewed from cereal grains",
    "p_transaction": true,
    "prices":        { "buy": "2,150", "sell": "86", "repair": null },
    "effects": [
        "Worker Stamina Recovery +2",
        "(Use through the Worker Menu on the World Map)."
    ],
    "lifespan":      null,
    "duration":      null,
    "cooldown":      null
}

Scraping the Full Item

When scraping for the full item, the Scraper will make extra requests in order to get the data for the recipes, designs, etc. Those requests are done after the first request is done and the Scraper has verified that the items exists. This means the promise will take more time to finish, specially if the internet connection is slow.

To get the full item, simply import the scraper and pass an id and a language flag if needed.

const { Item } = require('bdo-scraper')
async () => {
    const data = await Item(9213)
    console.log(data)
}

If succesful, this would return an object like:

{
    ...,
    "recipes": [
        {
            "id":        122,
            "icon":      "/items/new_icon/03_etc/07_productmaterial/00009213.png",
            "name":      "Beer",
            "skill_lvl": "Beginner 1",
            "exp":       400,
            "type":      "Cooking",
            "materials": [
                {
                    "link":   "/us/materialgroup/1/",
                    "icon":   "/items/new_icon/03_etc/07_productmaterial/00007005.png",
                    "amount": 5,
                    "id":     1,
                },
                ...
            ],
            "results": [...]
        },
        ...
    ],
    "used_in_recipe": [...]
}