コード例 #1
0
ファイル: Book.py プロジェクト: inderjot29/AmazonBook
 def solveRightCol(self):
     try:
         divRightCol = self.html.xpath(".//div[@id='rightCol']")[0]
         divBuyBoxInner = divRightCol.xpath(".//div[@id='buyBoxInner']")[0]
         priceSpan = divBuyBoxInner.xpath("./div/div[2]/ul/li/span")
         if len(priceSpan) == 0:
             self.listPrice = 0
         else:
             priceType = priceSpan[0].xpath("./span")[0].text.strip()
             priceValue = priceSpan[0].xpath("./span")[1].text.strip()
             if priceType == 'List Price:':
                 self.listPrice = CommonTool.strToFloat(priceValue)
             else:
                 self.listPrice = 0
             del priceType
             del priceValue
         del priceSpan
         del divBuyBoxInner
         del divRightCol
     except Exception, e:
         print 'RightCol error: %s' % str(e)
         self.listPrice = 0
コード例 #2
0
ファイル: Book.py プロジェクト: inderjot29/AmazonBook
 self.paperbackPrice = 0
 priceList = divCenterCol.find(".//div[@id='tmmSwatches']/ul")
 if priceList is None:
     priceList = divCenterCol.xpath(
         ".//div[@id='twister']/div/span[@class='a-declarative']/table/tr\
         ")
     for price in priceList:
         try:
             priceType = price.xpath(
                 './td[@class="dp-title-col"]/*[@class="title-text"]/span\
                 ')[0].text.strip()
             priceValue = price.xpath(
                 "./td[@class='a-text-right dp-price-col']//span")[0]\
                 .text.strip()
             if cmp(priceType, 'Kindle') == 0:
                 self.kindlePrice = CommonTool.strToFloat(priceValue)
             elif cmp(priceType, 'Hardcover') == 0:
                 self.hardcoverPrice = CommonTool.strToFloat(priceValue)
             elif cmp(priceType, 'Paperback') == 0:
                 self.paperbackPrice = CommonTool.strToFloat(priceValue)
         except Exception, e:
             pass
 else:
     priceList = priceList.xpath(".//li")
     for priceLi in priceList:
         spans = priceLi.xpath("./span/span/span/a/span")
         priceType = spans[0].text.strip()
         priceValue = spans[1]
         if priceValue.find("./span") is not None:
             priceValue = priceValue.find("./span").text.strip()
         else: