I have scraped three lists from a website and they get printed out into Selenium. Those being Team, odds and Href. However, these lists do not get written to a CSV file correctly. I want each list to be put into column 1, 2 and 3. Any help?
I tend to get lots of: <selenium.webdriver.remote.webelement.WebElement (session="211dc26889dedb4d1d5db5f355c9b225", element="0.936313100855265-9")>
My data looks like this: https://ibb.co/iW6rbk
What I want it to look like: https://ibb.co/fhna2Q
I believe this is caused by it writing the web elements instead of what I actually want. Any suggestions on how I can adjust my code so it actually writes what I want (the scraped values)?
Thanks
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import csv
import requests
import time
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Brother\chromedriver.exe')
driver.set_window_size(1024, 600)
driver.maximize_window()
driver.get('https://www.bookmaker.com.au/sports/soccer/37854435-football-australia-australian-npl-2-new-south-wales/')
SCROLL_PAUSE_TIME = 0.5
# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
time.sleep( 5 )
#link
elems = driver.find_elements_by_css_selector("h3 a[Href*='/sports/soccer']")
for elem in elems:
print(elem.get_attribute("href"))
#TEAM
langs1 = driver.find_elements_by_css_selector(".row:nth-child(1) td:nth-child(1)")
for lang in langs1:
print (lang.text)
time.sleep( 10)
#ODDS
langs = driver.find_elements_by_css_selector(".row:nth-child(1) span")
for lang in langs:
print (lang.text)
time.sleep( 10 )
import csv
with open ('I AM HERE12345.csv','w') as file:
writer=csv.writer(file)
for row in langs, langs1, elems:
writer.writerow(row)
