I managed to finish a script to automate repetitive tasks. My first one on Python!So I am now in the process of automating the part where I have to retrieve the data and format it for the script to use.
Here are the relevant parts my code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import csv
ie = 'C:\\Users\\dd\\Desktop\\IEDriverServer32.exe'
print(ie)
Iebrowswer = webdriver.Ie(ie)
Iebrowswer.get('https://ww3.example.com/')
Iebrowswer.find_element_by_class_name('gridrowselect').click()
print(len(Iebrowswer.find_elements_by_class_name('gridrow')))
Gridcells = Iebrowswer.find_elements_by_class_name('gridcell')
Gridinfo = [i.text for i in Gridcells]
print(Gridinfo)
csvfile = 'C:\\Users\\dd\\Desktop\\CSV1.csv'
with open(csvfile, "w") as output:
writer = csv.writer(output, lineterminator='\n')
for val in Gridinfo:
writer.writerow(['val'])
I managed to get the information that I wanted. All of it. Right now, my biggest issue is what is happening to the data when I make my CSV. It's coming out all wrong. This is what I get when I print into the shell(a small example):
['5555', '1', 'Verified', '', '6666', '2', 'Verified', '']
My excel/csv file is being displayed vertically like this:
Columnl
[5555]
[1]
[Verified]
[ ]
[6666]
[2]
[Verified]
[ ]
What I want is for my data to displayed horizontally breaking after the empty space like this:
Column1 Column2 Column3 Column4
5555 1 Verified
6666 2 Verified
- How do I achieve this?
I've looked over the documentation and a bunch of other questions on here, but I'm not closer to understanding the csv library and its arguments at all. It always seems that I get stuck on these really simple things. The only thing I succeeded in was adding even more columns to vertically display data taunting myself.