當前位置: 首頁>>代碼示例>>Python>>正文


Python Request.meta["Item"]方法代碼示例

本文整理匯總了Python中scrapy.http.request.Request.meta["Item"]方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.meta["Item"]方法的具體用法?Python Request.meta["Item"]怎麽用?Python Request.meta["Item"]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scrapy.http.request.Request的用法示例。


在下文中一共展示了Request.meta["Item"]方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_offers

# 需要導入模塊: from scrapy.http.request import Request [as 別名]
# 或者: from scrapy.http.request.Request import meta["Item"] [as 別名]
    def parse_offers(self, response):
        sel = Selector(response)
        asin = response.meta["ASIN"]

        # Build the item
        item = AmazonwishlistItem()
        item["ASIN"] = asin
        item["URL"] = "https://www.amazon.co.uk/dp/%s/?tag=eyeforfilm-21" % asin
        item["Title"] = tidy_up_text(
            [x for x in sel.xpath("//div[@id='olpProductDetails']//h1/text()").extract() if x.strip()][0])
        item["Other_Data"] = tidy_up_text(
            [x for x in sel.xpath('//div[@id="olpProductByline"]/text()').extract() if x.strip()][0])
        item["Other_Data"] = extraneous_other_data.sub(r'', item["Other_Data"])
        item["Type"] = sel.xpath("//select[@id='searchDropdownBox']/option[@selected='selected']/text()").extract()[0]
        item["Amazon_Price"] = response.meta.get('Amazon_Price', '')
        item["Original_URL"] = response.meta['Original_URL']

        # Amazon (almost) always returns the lowest priced offer - so take the first
        prices = sel.xpath("//div[contains(@class,'olpOffer')]")[1:]
        if prices:
            cheapestprice = prices[0].xpath(
                './/span[@class="a-size-large a-color-price olpOfferPrice a-text-bold"]/text()').extract()
            basecost = float(strip_non_price(cheapestprice[0]))
            cheapestshipping = prices[0].xpath('.//span[@class="olpShippingPrice"]/text()').extract()
            shipping = float(strip_non_price(cheapestshipping[0])) if cheapestshipping else 0.0
            item["Cheapest"] = basecost + shipping
            item["Cheapest_Condition"] = tidy_up_text(prices[0].xpath('.//h3/text()').extract()[0])
            if "Cheapest" in item and "Amazon_Price" in item and item["Cheapest"] and item["Amazon_Price"]:
                item["Cheapest_Cost_Ratio"] = round(float(item["Cheapest"]) / float(item["Amazon_Price"]), 3)

        # Re-sift for free shipping
        free_shipping = [x for x in prices if x.xpath('.//span[@class="supersaver"]')]
        if free_shipping:
            free_shipping_price = free_shipping[0].xpath(
                './/span[@class="a-size-large a-color-price olpOfferPrice a-text-bold"]/text()').extract()[0]
            item["Prime_Price"] = strip_non_price(free_shipping_price)
            item["Prime_Condition"] = tidy_up_text(free_shipping[0].xpath('.//h3/text()').extract()[0])
            if "Prime_Price" in item and "Amazon_Price" in item and item["Prime_Price"] and item["Amazon_Price"]:
                item["Prime_Cost_Ratio"] = round(float(item["Prime_Price"]) / float(item["Amazon_Price"]), 3)
            yield item
        else:
            # If there are no free shipping offers on this page, create a second request to make sure.
            request = Request('https://www.amazon.co.uk/gp/offer-listing/%s/ref=olp_prime_all?shipPromoFilter=1' % asin,
                              callback=self.parse_freeshipping)
            request.meta["Item"] = item
            yield request
開發者ID:scotm,項目名稱:AmazonUKWishlistScraper,代碼行數:48,代碼來源:Amazon.py


注:本文中的scrapy.http.request.Request.meta["Item"]方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。