aboutsummaryrefslogtreecommitdiff
path: root/src/ee/digikey/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/digikey/__init__.py')
-rw-r--r--src/ee/digikey/__init__.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py
index d0405f1..2fe7443 100644
--- a/src/ee/digikey/__init__.py
+++ b/src/ee/digikey/__init__.py
@@ -79,6 +79,13 @@ class PriceBreak(object):
self.per_quantity_price = per_quantity_price
+class Document(object):
+ def __init__(self, kind: str, title: str, url: str):
+ self.kind = kind
+ self.title = title
+ self.url = url
+
+
@total_ordering
class DigikeyProduct(object):
def __init__(self, part_number, mpn, url, attributes: List["DigikeyAttributeValue"] = None, categories=None):
@@ -90,6 +97,7 @@ class DigikeyProduct(object):
self.quantity_available = None
self.description = None
self.price_breaks: List[PriceBreak] = []
+ self.documents: List[Document] = []
assert self.part_number
assert self.mpn
@@ -303,6 +311,7 @@ class DigikeyParser(object):
if part_number and mpn:
p = DigikeyProduct(part_number, mpn, url, attributes, categories)
p.price_breaks = self._parse_price_breaks(tree)
+ p.documents = self._parse_documents(tree)
for n in tree.xpath("//*[@itemprop='description']"):
p.description = _to_string(n)
return p
@@ -348,6 +357,38 @@ class DigikeyParser(object):
return price_breaks if ok else []
@staticmethod
+ def _parse_documents(tree: html) -> List[Document]:
+ docs = []
+
+ for row in tree.xpath("//*[@class='product-details-documents-media product-details-section']//tr"):
+ # print("row={}".format(row))
+ kind: str = _first(row.xpath(".//th/text()"))
+
+ if not kind:
+ continue
+
+ kind = kind.strip()
+
+ for a in row.xpath(".//td//a[not(contains(@class, '-expander-toggle'))]"):
+ # print("a={}".format(a))
+ title = a.text
+ if not title:
+ continue
+ title = title.strip()
+
+ href = a.get("href")
+ if not href:
+ continue
+
+ href = href.strip()
+ if href.startswith("//"):
+ href = "https:" + href
+
+ docs.append(Document(kind, title, href))
+
+ return docs
+
+ @staticmethod
def _handle_product_table(tree: html, res: DigikeySearchResponse):
products = tree.xpath("//*[@itemtype='http://schema.org/Product']")