Writing Python Selenium Output To Excel
I have written a script to scrape product information from online websites. The goal is to write these information out to an Excel file. Due to my limited Python knowledge, I only
Solution 1:
I usually find that writing to CSV is the safest way to get data into excel. I use something like the following code:
import csv
import sys
import time
import datetime
from os import fsync
ts=time.time() #get the time, to use in a filename
ds=datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M') #format the time for the filename
f2=open('OutputLog_'+ds+'.txt','w') #my file is output_log + the date time stamp
f2.write(str('Column1DataPoint'+','+'Column2DataPoint') #write your text, separate your data with comma's
#if you're running a long loop, and want to keep your file up to date with the proces do these two steps in your loop too
f2.flush()
fsync(f2.fileno())
#once the loop is finished and data is writtin, close your file
f2.close()
I think for you, the change to the above code would be to change the write line something like the following:
f2.write(str(i+','+name.encode("utf-8")+','+prodNum+','+output.text)
Post a Comment for "Writing Python Selenium Output To Excel"