簡體   English   中英

csv文件輸出新行

[英]csv file output new line

我有可以從 . txt文件並獲取電話號碼並將其保存到csv文件一切正常,但在新行中輸出每個數字這是我的代碼

def writecsv(namefile,type,header=None):
    with open(namefile, 'w') as f:
        w = csv.writer(f)
        if header is not None:
            w.riterow(header)
        for row in type:
            w.writerow(row)
        try:
            a = driver.find_element_by_css_selector('#pagelet_contact > div > div._4qm1 > ul > li:nth-child(1) > div > div._4bl7._3xdi._52ju > span')
            print (a.text)
            if a.text != 'Mobile phones':
                not_found_account.append(account)
                print ("{0} not found".format(account))
            else:
                phone = driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div/div[2]/div[2]/div[1]/div/div[2]/div/div/div[1]/div[2]/div/ul/li/div/div[2]/div/div/div[1]/div/div[1]/ul/li[1]/div/div[2]/div/div/span/ul/li/span').text
                                print (phone.text)
                active_account.append(account)
                print ("{0} active account".format(account))
        except:
            print (phone)
            continue
    print (phone)
    writecsv('facebook/FB_available_account.csv', phone)

python 打印看起來非常好

100003187973663?sk=about&section=contact-info
Mobile phones
+20 1125067822

但 csv 文件中的輸出看起來像這樣

+

2

0



1

1

2

etc..

請問哪里錯了? 謝謝

要在每個單元格中寫入,示例是

import csv

my_data = "Example"

with open("FB_available_account.csv", "w") as csv_file:
    csv_writer = csv.writer(csv_file)
    csv_writer.writerow([my_data])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM