Shopping at LEGO or Amazon?
Please use our links: LEGO.comAmazon
As an Amazon Associate we earn from qualifying purchases.

Get Minifig-IDs from a set

LebosteinLebostein Member Posts: 53
edited May 2019 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 Administrator Posts: 7,076
    No -- because that information comes from BrickLink and it would be inappropriate for us to share it.
  • CCCCCC Member Posts: 20,526
    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 Member Posts: 712
    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.

Shopping at LEGO.com or Amazon?

Please use our links: LEGO.com Amazon

Recent discussions Categories Privacy Policy Brickset.com

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Brickset.com is a participant in the Amazon Services LLC Associates Program, the Amazon.com.ca, Inc. Associates Program and the Amazon EU Associates Programme, which are affiliate advertising programs designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.

As an Amazon Associate we earn from qualifying purchases.