I need help figuring out how to output the end result of this python to a csv (C:/temp/test.csv) file. Write now it prints it to the prompt. I tried using write, but I kept getting errors no matter what I tried. My main goal is to output the information to the csv without the html included and to have commas separating each result (result2, result3, result4, result5). But right now i would just be happy with being able to output it the way it is to a csv file. Then I can work on the rest.
from selenium import webdriver
import time
from bs4 import BeautifulSoup
import csv
driver = webdriver.Chrome('C:/temp/chromedriver_win32/chromedriver.exe')
driver.get('https://www.dell.com/support/home/en-us/product-support/product/precision-15-5520-laptop/drivers')
time.sleep(3)
element = driver.find_element_by_xpath("//button[contains(.,'Show all')]").click();
page = driver.page_source
driver.close()
soup = BeautifulSoup(page,'html.parser')
results = soup.find(id='downloads-table')
results2 = results.find_all(class_='dl-desk-view')
results3 = results.find_all(class_='details-control sorting_1')
results4 = results.find_all(class_='details-control')
results5 = results.find_all(class_='btn-download-lg btn btn-sm no-break text-decoration-none dellmetrics-driverdownloads btn-outline-primary')
open('C:/temp/Precision_5520.csv', "w").close
with open('C:/temp/Precision_5520.csv', "a") as csvfile:
writer = csv.writer(csvfile)
for r2, r3, r4, r5 in zip(results2, results3, results4, results5):
writer.writerow([results2, results3, results4, results5])