Код: Выделить всё
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 bs4 import BeautifulSoup
import time
# Function to scrape announcements
def scrape_announcements():
chrome_options = Options()
chrome_options.binary_location = 'C:/Users/HP/Downloads/chrome-headless-shell-win64 (1)/chrome-headless-shell-win64/chrome-headless-shell.exe'
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
try:
driver.get('https://www.nseindia.com/companies-listing/corporate-filings-announcements')
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.ID, 'CFanncEquityTable')))
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
table = soup.find('table', {'id': 'CFanncEquityTable'})
if table:
for row in table.find_all('tr'):
cells = row.find_all('td')
for cell in cells:
print(cell.text.strip())
print("-----------------------------")
else:
print("Table not found.")
finally:
driver.quit()
# Main function
def main():
scrape_announcements()
if __name__ == "__main__":
main()
Код: Выделить всё
selenium.common.exceptions.TimeoutException: Message:
Я попытался дождаться присутствия элемента с идентификатором «CFanncEquityTable» на веб-странице «https://www.nseindia.com/companies-list ... ouncements» с использованием Selenium WebDriver в Python. Я ожидал, что WebDriver будет ждать указанное время (60 секунд), пока элемент не появится на странице. Однако я столкнулся с исключением TimeoutException, указывающим, что элемент не был найден в течение указанного периода времени. По сути, моя цель — извлечь данные из таблицы.
Подробнее здесь: https://stackoverflow.com/questions/783 ... -webdriver