When using Python crawlers or anything else, the CSV store and read related operations are used, and here we talk about:
The CSV (comma-separated values) comma delimiter, which is a semicolon-delimited list of values and values in each record.
First, read the document
ImportCsv#Import the CSV library fromItertoolsImportIslice#Importing this package has a great effect when the first row of the CSV file is not read#read the China_city_aqi.csv file, read it in R, encode is Utf-8With open ("China_city_aqi.csv","R", encoding ="Utf-8") as F:#put CSV-read files in readerReader =Csv.reader (f)#after traversing, Islice (reader, 1, None) reads the first line in the reader file to the last line, and of course you can change to the end of the line forLineinchIslice (Reader, 1, None):#Read nameName = Line[:1] #read the data after the nameValue = line[1:] Print(Name,' ', value)
Second, write the document
Importcsvheaders= ['Apple','Banana','Apple']#newline: Indicates a newline, by default ' \ n 'File = Open ('Writer.csv','W', encoding='Utf-8', newline="') Writer=csv.writer (file) writer.writerow (headers)
Python's CSV operation