如何自动从Digi-Key检索零件信息


15

在给定Digi-Key零件编号的情况下,如何自动检索制造商,制造商零件编号,描述等信息。也许解析GET http的目的是:

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

(感谢愤怒的人提供正确的参数)

其中DK_PART_NUMBER是Digikey零件号。

是否有人知道他们是否拥有Web服务或仅是更好的接口?


问了这个问题之后,我决定继续写一些可以从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

仅捕获[价格中断/单价/扩展价格]表的第一条数据行。


4
Digikey现在提供了用于搜索和订购的Web服务,并为此提供了
apalopohapa

3
BeautifulSoup可能是python最好的HTML解析器。比内置的东西好得多。
康纳·沃尔夫,2014年

Answers:


8

您想使用detail选项代替关键字。像这样:

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

返回一个HTML页面,该页面是可以解析的文本。它们全部采用表格格式,因此您可以创建感兴趣的术语列表并解析出值。我可以看到一个零件清单脚本,其中包含零件清单和要检索的值(例如,电压,最大电流,或者Digikey列出了它),然后用一些Python读取零件编号,抓取页面,解析信息并将其粘贴到CSV,数据库或HTML文件中。我一直在想类似的事情,似乎并不难。好吧,足以阻止我立即将其删除:)


7

也许您可以通过Octopart的API来做到这一点


1
在他们的文档页面上,您似乎可以过滤供应商(在这种情况下为DigiKey),尽管我只是在DigiKey的网站上搜索了一些零件,而Octopart在结果中没有提及DigiKey。
Flyguy 2010年

1
显然Digikey特别要求他们不要在搜索中包含他们。
apalopohapa

1
从那以后改变了,结果中包括了Digikey。甚至在今年以前,Octopart也没有显示Digi-key的搜索结果。看来他们已经使用Digi-Key解决了问题,现在Octopart显示了Digi-key的结果
Kortuk 2013年

1
我直接针对Digikey运行我自己的python脚本并查询Octopart API,但结果却有所不同。另外,直接针对digikey编码我可以跟随同一部分的替代包装链接,我认为Octopart不能正确映射此内容。
kert 2014年

4

当前的最佳答案是https://services.digikey.com/, 因为Digi-Key搜索Web服务(SWS)和Ordering Web Service(OWS)为客户提供了对Digi-Key庞大的产品数据库和订购的实时访问。系统。'。

您正在执行的是“屏幕抓取”,当DigiKey更新其网站时,该屏幕很容易损坏。


1
是。在2010年,当这些服务尚不存在时,有人问过这个问题。当时,“屏幕刮擦”是最好的解决方案。当然,在更新系统/接口/ API时,任何技术都容易受到破坏。
apalopohapa


2

如果您将BOM保留为MS Excel电子表格,则可以通过Data-> Get External Data-> From Web将价格直接拉入工作表。我正在使用Excel2010。这是我使用宏记录器创建的宏。

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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.