Als neuer Benutzer konnte ich eine Spider machen strampler E-Commerce-Website und extrahieren Titel und Variationen von jedem Produkt und die Ausgabe CSV-Datei und eine Produktlinie, aber was ich will Dies ist eine Variation von Linie, bitte kann mir jemand helfen, in meinem Projekt voranzukommen.scrapy CSV schreiben
Ich freue mich auf die Frage zu kommen, aber leider kann ich keine Antwort finden.
meine Spinne:
import scrapy
from w3lib.html import remove_tags
from products_crawler.items import ProductItem
class DemostoreSpider(scrapy.Spider):
name = "demostore"
allowed_domains = ["adns-grossiste.fr"]
start_urls = [
'http://adns-grossiste.fr/17-produits-recommandes',
]
download_delay = 0.5
def parse(self, response):
for category_url in response.css('#categories_block_left > div > ul > li ::attr(href)').extract():
yield scrapy.Request(category_url, callback=self.parse_category, meta={'page_number': '1'})
def parse_category(self, response):
for product_url in response.css('#center_column > ul > li > div > div.right-block > h5 > a ::attr(href)').extract():
yield scrapy.Request(product_url, callback=self.parse_product)
def parse_product(self, response):
item = ProductItem()
item['url'] = response.url
item['title'] = response.css('#center_column > div > div.primary_block.clearfix > div.pb-center-column.col-xs-12.col-sm-7.col- md-7.col-lg-7 > h1 ::text').extract_first()
item['Déclinaisons'] = remove_tags(response.css('#d_c_1852 > tbody >tr.combi_1852.\31 852_155.\31 852_26.odd > td.tl.sorting_1 > a > span ::text').extract_first() or '')
yield item
Probe CSV Wunsch: image CSV
Mögliches Duplikat von [Scrapy-Pipeline, um die CSV-Datei im richtigen Format zu exportieren] (https://stackoverflow.com/questions/29943075/scrap-ypipeline-to-export-csv-file-in-the-right-format) –