My main goal is to scrape content from the table from this site
polygonscan.com/token/0x64a795562b02830ea4e43992e761c96d208fc58d
For example, I tried to select content from the table - then I wanted to scrape all the data from the table to a .csv file, but I ran into a problem at the start of this task. I tried to select content from the first row, but it looks like Selenium doesn't see any HTML content from the table area. My code below:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
# Options
chrome_options = Options()
chrome_options.add_argument("--headless")
# Set drive
chrome_driver_path = r"C:\Users\kacpe\OneDrive\Pulpit\Python\Projekty\chromedriver.exe"
driver = webdriver.Chrome(chrome_driver_path, options=chrome_options)
driver.get("https://polygonscan.com/token/0x64a795562b02830ea4e43992e761c96d208fc58d")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//table/tbody/tr[0]")))
print(element)
except TimeoutException as e:
print(e)
and the error I receive:
ile "C:\Users\kacpe\OneDrive\Pulpit\Python\Projekty\nc-coin-scraper\nc_scraper\nc_scraper\spiders\aaa.py", line 29, in <module>
a = driver.find_element(By.XPATH, '//*[@id="maindiv"]/div[1]/p').text
File "C:\Users\kacpe\OneDrive\Pulpit\Python\Projekty\nc-coin-scraper\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1244, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\kacpe\OneDrive\Pulpit\Python\Projekty\nc-coin-scraper\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
self.error_handler.check_response(response)
File "C:\Users\kacpe\OneDrive\Pulpit\Python\Projekty\nc-coin-scraper\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="maindiv"]/div[1]/p"}
(Session info: headless chrome=97.0.4692.71)
Stacktrace:
Backtrace:
Ordinal0 [0x00EC6903+2517251]
Ordinal0 [0x00E5F8E1+2095329]
Ordinal0 [0x00D62848+1058888]
Ordinal0 [0x00D8D448+1233992]
Ordinal0 [0x00D8D63B+1234491]
Ordinal0 [0x00DB7812+1406994]
Ordinal0 [0x00DA650A+1336586]
Ordinal0 [0x00DB5BBF+1399743]
Ordinal0 [0x00DA639B+1336219]
Ordinal0 [0x00D827A7+1189799]
Ordinal0 [0x00D83609+1193481]
GetHandleVerifier [0x01055904+1577972]
GetHandleVerifier [0x01100B97+2279047]
GetHandleVerifier [0x00F56D09+534521]
GetHandleVerifier [0x00F55DB9+530601]
Ordinal0 [0x00E64FF9+2117625]
Ordinal0 [0x00E698A8+2136232]
Ordinal0 [0x00E699E2+2136546]
Ordinal0 [0x00E73541+2176321]
BaseThreadInitThunk [0x75DAFA29+25]
RtlGetAppContainerNamedObjectPath [0x77DE7A9E+286]
RtlGetAppContainerNamedObjectPath [0x77DE7A6E+238]
Any thoughts on how to handle this problem?