Please refrain from posting animated GIFs, memes, joke videos and so on in discussions other than those in the off topic area.

Dismiss this message to confirm your acceptance of this additional forum term of use.

Get Minifig-IDs from a set

LebosteinLebostein GermanyMember Posts: 1
edited May 7 in The Database
I read some set informations with Python + API. For example I can get the number of Minifigs of a set. It is possible to get a list of Minifig IDs of a set (for example [sw0009, sw0019, sw0028, sw0034] in 7140-1)?



Comments

  • HuwHuw Brickset Towers, Hampshire, UKAdministrator Posts: 6,390
    No -- because that information comes from BrickLink and it would be inappropriate for us to share it.
  • CCCCCC UKMember Posts: 17,515
    You might be able to scrape the data yourself direct from BL from their minifigure listings. For example, if you use this URL


    It just lists the minifigure data for that set and from the page source  you will be able to scrape the minifigure data.

    Alternatively, you could do it the other way around, for every minifigure you could scrape the sets they appear in using a URL like this


  • benbacardibenbacardi EnglandMember Posts: 320
    Yes, it really is very easy to scrape the page ;-) Although do BrickLink have an API you could use?

    $ python3
    Python 3.7.2 (default, Feb 12 2019, 08:15:36)
    [Clang 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import requests
    >>> import bs4
    >>> import re
    >>>
    >>> set_id = 7140
    >>>
    >>> soup = bs4.BeautifulSoup(requests.get('https://www.bricklink.com/catalogItemInv.asp?S={}-1&viewItemType=M'.format(set_id), headers={'User-Agent': 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8'}).content)
    >>>
    >>> [x.text for x in soup.findAll('a', href=re.compile(r'^/v2/catalog/catalogitem\.page\?M='))]
    ['sw0009', 'sw0019', 'sw0028', 'sw0034']
    >>>

Sign In or Register to comment.
Recent discussions Categories Privacy Policy