15
\$\begingroup\$

How to automatically retrieve, given a Digi-Key part number, information such as Manufacturer, Manufacturer Part Number, Description, etc. Perhaps parsing the GET http respose to:

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=DK_PART_NUMBER

(thanks to angryee for the correct parameters)

Where DK_PART_NUMBER is the Digikey part number.

Does anybody know if they have a web service or simply a better interface for this?


After asking this question I decided to go ahead and write something that did some basic fetching from Digikey:

dk_pn = '587-1962-1-ND'

from urllib import urlopen
from sgmllib import SGMLParser

headers = ['Digi-Key Part Number',
           'Manufacturer',
           'Manufacturer Part Number',
           'Description',
           'Lead Free Status / RoHS Status',
           'Operating Temperature',
           'Standard Package',
           'Price Break',
           'Unit Price',
           'Extended Price']

class DK_Parser(SGMLParser):
    def reset(self):

        SGMLParser.reset(self)

        self.last_td = ''
        self.inside_th = False
        self.inside_td = False
        self.grab_data = False
        self.part_info = {}
        self.hdr_index = 0
        self.row_hdrs = []

    def start_tr(self, attrs): # row
        self.first_header_in_row = True

    def start_th(self, attrs): # header cell
        if self.first_header_in_row:
            self.first_header_in_row = False
            self.row_hdrs = []
            self.hdr_index = 0
        self.inside_th = True

    def end_th(self):
        self.inside_th = False

    def start_td(self, attrs): # data cell
        self.inside_td = True

    def end_td(self): 
        self.inside_td = False
        self.hdr_index = self.hdr_index+1

    def handle_data(self,text):
        text = text.strip()
        if self.inside_th:
            if text in headers:
                self.row_hdrs.append(text)
                self.last_td = ''
                self.grab_data = True
            else:
                self.grab_data = False
        elif self.inside_td and self.grab_data:
            if self.hdr_index:
                self.last_td = ''
            if self.hdr_index < len(self.row_hdrs):
                self.last_td = self.last_td + text
                self.part_info[self.row_hdrs[self.hdr_index]] = self.last_td

dk_url = 'http://search.digikey.com/scripts/DkSearch/dksus.dll'
dk_params = '?Detail&name='

sock = urlopen(dk_url + dk_params + dk_pn)

parser = DK_Parser()
parser.feed(sock.read())
sock.close()
parser.close()

for k,v in parser.part_info.items():
    print k,":",v

Only the first data line of the the [price break/unit price/extended price] table is captured.

\$\endgroup\$
3

6 Answers 6

9
\$\begingroup\$

You'd want to use the detail option instead of the keyword. Like this:

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=458-1003-ND

That returns an HTML page which is text which can be parsed. It's all in table format so you can create a list of terms you're interested in and parse out the values. I can see a parts list script that takes in a list of parts and the values you want to retrieve (ie, Voltage, Max Current, or however Digikey lists it) and then make some Python to read the part number, grab the page, parse out the info and stick it in a CSV, database or HTML file. I've been thinking of something similar and it doesn't seem too hard. Well, hard enough to stop me from whipping it out right now anyway :)

\$\endgroup\$
7
\$\begingroup\$

Perhaps you could do it through Octopart's API?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ From their documentation page, it looks like you can filter on supplier (DigiKey, in this case), although I just searched for a handful of parts on DigiKey's website and Octopart didn't mention DigiKey in the results. \$\endgroup\$
    – Flyguy
    Commented Jul 8, 2010 at 12:00
  • 1
    \$\begingroup\$ Apparently Digikey has specifically asked them not to inlude them in their search. \$\endgroup\$ Commented Sep 27, 2010 at 5:36
  • 2
    \$\begingroup\$ That has since changed, Digikey is included in the results.Previously, this year even, Octopart did not show search results from Digi-key. It seems they have worked something out with Digi-Key and now Octopart displays results from Digi-key \$\endgroup\$
    – Kortuk
    Commented Jan 11, 2013 at 0:25
  • 1
    \$\begingroup\$ I am running my own python script directly against Digikey and querying Octopart API and i am getting different results. Also, coding directly against digikey i can follow alternate packaging links for the same part, i dont think Octopart maps this properly. \$\endgroup\$
    – kert
    Commented Apr 12, 2014 at 17:46
4
\$\begingroup\$

The current best answer is https://services.digikey.com/ as 'The Digi-Key Search Web Service (SWS) and Ordering Web Service (OWS) provide clients with real-time access to Digi-Key’s vast product database and ordering system.'.

What you're doing is "screen scraping", which is vulnerable to breaking as DigiKey updates their website.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Yes. This was asked in 2010 when the those services didn't exist yet. "screen scraping" was the best solution back then. Of course, any technique is vulnerable to breaking when the systems/interfaces/API get updated. \$\endgroup\$ Commented May 7, 2015 at 20:16
2
\$\begingroup\$

Here's sample code in python, ruby and JS to do this with Octopart's API

http://octopart.com/api/docs/v3/overview#bom-matching

You can filter out for Digikey at the application level.

\$\endgroup\$
2
\$\begingroup\$

If you keep your BOM as a MS Excel spreadsheet, you can pull the prices directly into a worksheet via Data->Get External Data->From Web. I'm using Excel 2010. Here is a macro that I made using the macro recorder.

Sub addDigikeyPriceExample()
    'http://www.digikey.com/product-detail/en/MANUFACTURERPARTNUM/DIGIKEYPARTNUM/PACKAGINGNUM ?
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.digikey.com/product-detail/en/SI4707-B20-GM/336-2147-ND/2686997" _
        , Destination:=Range("$A$1"))
        .Name = "2622997" 'make random number?
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = """pricing"""
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub
\$\endgroup\$
0
\$\begingroup\$

You can create a custom Chrome search engine.

  1. go to Chrome settings

  2. click search engine > Manage search engines and site search

  3. under Site Search, click Add

  4. Enter

    Search engine: Digikey

    Shortcut: di

    URL: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=%s

To test:

  1. Open a new tab
  2. In address bar type di and press spacebar
  3. Enter desire part number

https://groovypost.com/howto/add-custom-search-engine-chrome

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.