def grab_product(self, flag, url): product = Product() # 来源 product.flag = flag # 源链接 product.url = url # 状态正常 product.status = "1" # 英文 product.language_id = "2" pg = self.do_visit(url) # 解析商品信息 if self.ana_product_info(product, pg): # 保存商品信息 self.save_product(product) # 保存描述信息 self.save_product_desc(product) # 保存图片信息 pimg = ProductImages() pimg.spid = product.spider_product_id if len(product.images) > 0: pimg.images = ",".join(product.images) self.save_product_images(pimg) else: # 记录没有图片的商品 self.log_info("".join([str(pimg.spid), " no images!"])) psku = ProductSku() # 保存sku信息 self.ana_and_save_product_sku(psku, product) else: self.log_info("".join([url, " product not saved!"]))
def save_product_images(product, pidao): pimg = ProductImages() pimg.spid = product.spider_product_id images = product.images img_arr = [] for img in images: img_url = "".join([img['url'], "?wid=750"]) img_arr.append(img_url) pimg.images = ",".join(img_arr) if pidao.is_exists_product_images(pimg.spid): # pidao.update_product_images(pimg) print "".join([str(pimg.spid), " images is exists!"]) else: pidao.save(pimg)
def grab_product(self, flag, url): product = Product() # 来源 product.flag = flag # 源链接 product.url = url # 状态正常 product.status = "1" # 英语 product.language_id = "2" pg = self.do_visit(url) # 解析商品信息 if self.ana_product_info(product, pg): # 保存商品信息 self.save_product(product) # 保存描述信息 self.save_product_desc(product) pimg = ProductImages() pimg.spid = product.spider_product_id img_arr = [] if len(product.images) > 0: for img in product.images: # -20后缀结束的图片不是需要的图片 if "-20." in img: continue img_arr.append(img) pimg.images = ",".join(img_arr) # 保存图片信息 self.save_product_images(pimg) else: # 记录没有图片的商品 self.log_info("".join([str(pimg.spid), " no images!"])) psku = ProductSku() # 解析并保存sku信息 self.ana_and_save_product_sku(psku, product, pg) else: self.log_info("".join([url, " product not saved!"]))