📅  最后修改于: 2022-03-11 14:45:03.701000             🧑  作者: Mango
def parse_book(self, response):
book_loader = ItemLoader(item=BookItem(), response=response)
book_loader.default_input_processor = MapCompose(remove_tags)
book_loader.add_value("image_urls", response.urljoin(response.css(".item.active > img::attr(src)").extract_first()))
book_loader.add_css("title", ".col-sm-6.product_main > h1", TakeFirst())
book_loader.add_css("price", ".price_color", TakeFirst())
book_loader.add_css("upc", ".table.table-striped > tr:nth-child(1) > td", TakeFirst())
book_loader.add_css("product_type", ".table.table-striped > tr:nth-child(2) > td", TakeFirst())
book_loader.add_css("tax", ".table.table-striped > tr:nth-child(5) > td", TakeFirst())
book_loader.add_css("stock", ".table.table-striped > tr:nth-child(6) > td", TakeFirst())
book_loader.add_css("reviews", ".table.table-striped > tr:nth-child(7) > td", TakeFirst())
book_loader.add_css("rating", ".star-rating::attr(class)", TakeFirst())
return book_loader.load_item()