import csv
csv_output = csv.writer(open("output.csv", "wb")) # output.csv is the output file name!
csv_output.writerow(["Col1","Col2","Col3","Col4"]) # Setting first row with all column titles
temp = []
deats = soup.find_all('p')
for n in deats:
temp.append(str(n.text))
csv_output.writerow(temp)
您可以将csv行创建为一个循环(或使用列表理解),为了便于阅读,我将显示显式循环,您可以自己将其更改为单个列表理解行。在
现在可以使用csv.Writer()
您可以使用csv模块进行此操作:
嘿,试着这样:
相关问题 更多 >
编程相关推荐