当前位置: 首页>>代码示例>>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;未经允许,请勿转载。