从第2列开始写空白值

时间:2017-11-01 04:11:04

标签: python csv selenium selenium-webdriver web-scraping

我正在抓取数据,但是我希望csv写入第2列到第12列或B-L而不是1-4。到目前为止,我只是简单地将langs_text写入列中,尽管这很慢。是否有一个更好的方法,不需要这么长时间,所以我可以从第2列开始?

我试图包含以下内容,但它根本不会向csv写入任何值并继续工作。

E.g

langs11 = ("potato")
langs11_text = []



   langs11 = []
    langs11_text = []

    time.sleep(0)
    FILE LOCATION = 'C:\\Users\\Bain3\\Aperture.csv'

    with open((FILE LOCATION), 'a', newline='', encoding="utf-8") as outfile:
        writer = csv.writer(outfile)
        for row in zip(langs11_text, langs_text, langs11_text, langs11_text, langs11_text, langs11_text, langs1_text, langs2_text, elem_href, langs11_text):
            print(row)
            writer.writerow(row)

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要的是下面的内容

for row in zip(langs_text, langs2_text, langs3_text):
    data = ["","","","","","","","","","","",""]
    data[1] = row[0]
    data[4] = row[1]
    data[6] = href
    data[7] = row[2]

    writer.writerow(data)