-1
Ich versuche, meine Datei über die Befehlszeile zu exportieren:Export Python Daten in CSV-Datei
scrapy crawl tunisaianet -o save.csv -t csv
aber nichts happenning, jede mögliche Hilfe?
hier ist mein Code:
import scrapy
import csv
from tfaw.items import TfawItem
class TunisianetSpider(scrapy.Spider):
name = "tunisianet"
allowed_domains = ["tunisianet.com.tn"]
start_urls = [
'http://www.tunisianet.com.tn/466-consoles-jeux/',
]
def parse(self, response):
item = TfawItem()
data= []
out = open('out.csv', 'a')
x = response.xpath('//*[contains(@class, "ajax_block_product")]')
for i in range(0, len(x)):
item['revendeur'] = response.xpath('//*[contains(@class, "center_block")]/h2/a/@href').re('tunisianet')[i]
item['produit'] = response.xpath('//*[contains(@class, "center_block")]/h2/a/text()').extract()[i]
item['url'] = response.xpath('//*[contains(@class, "center_block")]/h2/a/@href').extract()[i]
item['description'] = response.xpath('//*[contains(@class, "product_desc")]/a/text()').extract()[i]
item['prix'] = response.xpath('//*[contains(@class, "price")]/text()').extract()[i]
data = item['revendeur'], item['produit'], item['url'], item['description'], item['prix']
yield data
out.write(str(data))
out.write('\n')
Warum erstellen Sie ein Element, und dann pas Singen Sie das zu einem Tupel ?, und wenn Sie bereits in der Kommandozeile nach csv exportieren, warum brauchen Sie 'out.csv'? – eLRuLL
durchdachte.csv überschreibt Daten für jedes Mal, wenn ich den Befehl ausführte, aber es ist in Ordnung –
hat nicht [this] (http://stackoverflow.com/questions/36902783/output-python-to-csv-regular/36903483#) 36903483) Hilfe? – eLRuLL