I have a python code that downloads data from the table contained in a web page to a local csv file. The code has run into an exception saying an unknown error occurred. Please see below for details.
Error Message:
Traceback (most recent call last):
File "test.py", line 50, in <module>
wr.writerow([d.text for d in row.find_elements_by_css_selector('td')])
File "test.py", line 50, in <listcomp>
wr.writerow([d.text for d in row.find_elements_by_css_selector('td')])
File "C:\Users\username\PycharmProjects\Web_Scraping\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 76, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "C:\Users\username\PycharmProjects\Web_Scraping\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\username\PycharmProjects\Web_Scraping\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\username\PycharmProjects\Web_Scraping\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown error occurred while processing the specified command.
Python code:
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.common.exceptions import TimeoutException
import time
import csv
from datetime import datetime
# Locate Edge driver
driver = webdriver.Edge(executable_path = "C://Windows//SysWOW64//MicrosoftWebDriver.exe")
driver.maximize_window()
# Using Edge to open the steam website
driver.get("https://partner.steampowered.com")
# Pause the driver for better performance
driver.implicitly_wait(10)
# Enter email address
login_un = driver.find_element_by_id('username').send_keys("")
# Enter password
login_pw = driver.find_element_by_id('password').send_keys("")
# Click sign in tp log in
driver.find_element_by_id('login_btn_signin').click()
# Find the desired link
driver.find_element_by_link_text('Age of Empires II: Definitive Edition').click()
time.sleep(3)
# Locate the link for Current Players
driver.find_element_by_css_selector('#gameDataLeft > div:nth-child(1) > table > tbody > tr:nth-child(9) > td:nth-child(3) > a').click()
time.sleep(5)
# Locate 1 year for Current Players
driver.find_element_by_xpath('/html/body/center/div/div[3]/div[1]/em[1]').click()
# x.click()
time.sleep(3)
# Locate the table element
table = driver.find_element_by_css_selector('body > center > div > div:nth-child(13) > table')
# Open local csv and save data
filename = datetime.now().strftime('C:/Users/username/Desktop/Output/Concurrent_Players_%Y%m%d_%H%M.csv')
with open(filename, 'w', newline='') as csvfile:
wr = csv.writer(csvfile)
for row in table.find_elements_by_css_selector('tr'):
wr.writerow([d.text for d in row.find_elements_by_css_selector('td')])
print("Concurrent_Player data is saved. ")
HTML Source: (Sorry for not being able to provide the URL because this is an internal website. )
<div>
<table>
<tbody><tr>
<td></td>
<td></td>
<td align="right" title="2019-02-11 to 2020-02-09"><b>Most recent year</b></td>
<td></td> <!--Expandable percentage column-->
<td align="right"><b>Daily average during period<b></b></b></td>
<td align="right"><b>Change vs. previous period</b></td>
<td align="right"></td>
<td class="dim" align="right" title="2018-02-12 to 2019-02-10"><b>Previous year</b></td>
<td></td> <!--Expandable percentage column-->
<td class="dim" align="right"><b>Previous daily average<b></b></b></td>
</tr>
<tr>
<td>Average daily peak concurrent users </td>
<td></td>
<td align="right">4,032</td>
<td align="right"></td>
<td align="right">11</td>
<td align="right"><span style="color:#B5DB42;">+25971%</span></td>
<td width="16"></td>
<td class="dim" align="right">15</td>
<td class="dim" align="right"></td>
<td class="dim" align="right" width="100">0</td>
<td></td>
</tr>
<tr>
<td>Maximum daily peak concurrent users </td>
<td></td>
<td align="right">26,767</td>
<td align="right"></td>
<td align="right">74</td>
<td align="right"><span style="color:#B5DB42;">+51375%</span></td>
<td width="16"></td>
<td class="dim" align="right">52</td>
<td class="dim" align="right"></td>
<td class="dim" align="right" width="100">0</td>
<td></td>
</tr>
<tr>
<td>Average daily active users </td>
<td></td>
<td align="right">24,686</td>
<td align="right"></td>
<td align="right">68</td>
<td align="right"><span style="color:#B5DB42;">+70506%</span></td>
<td width="16"></td>
<td class="dim" align="right">35</td>
<td class="dim" align="right"></td>
<td class="dim" align="right" width="100">0</td>
<td></td>
</tr>
<tr>
<td>Maximum daily active users </td>
<td></td>
<td align="right">157,231</td>
<td align="right"></td>
<td align="right">432</td>
<td align="right"><span style="color:#B5DB42;">+191645%</span></td>
<td width="16"></td>
<td class="dim" align="right">82</td>
<td class="dim" align="right"></td>
<td class="dim" align="right" width="100">0</td>
<td></td>
</tr>
</tbody></table>
</div>
The code does generate a csv file as specified but no data is saved due to the error. I have other similar python codes implemented the same way and succeed. However, I'm not able to troubleshoot by myself on this one. I hope the information provided is enough for you to review. Thanks so much in advance!

