from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from bs4 import BeautifulSoup
import pandas as pd
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1920x1080")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
URL = 'https://gemelnet.cma.gov.il/views/dafmakdim.aspx'
driver.get(URL)
time.sleep(2)
review=WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='knisa']")))
review.click()
table=WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='Aaaa89455bbfe4387b92529246ea52dc6114']//font"))).text()
print(table)我正在尝试提取表,但他们给了我raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:如何解决这些错误的任何建议。
请告诉我我会犯什么错误,这是页面链接https://gemelnet.cma.gov.il/views/dafmakdim.aspx。

table

发布于 2022-11-30 09:50:48
这里有几个问题需要改进:
Aaaa89455bbfe4387b92529246ea52dc6114类是一个动态值。review=WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='knisa']")))WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='knisa']")))返回的web元素对象之前,time.sleep(2),也不需要将其存储到最初打印的显示“加载”内容的review临时variable.不理想,但以下几点是可行的:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)
url = "https://gemelnet.cma.gov.il/views/dafmakdim.aspx"
driver.get(url)
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='knisa']"))).click()
wait.until(EC.visibility_of_element_located((By.XPATH, "//td[contains(.,'קרנות השתלמות')]")))
time.sleep(2)
table = wait.until(EC.visibility_of_element_located((By.XPATH, "//table[@id='ReportViewer1_fixedTable']"))).text
print(table)产出如下:
30/11/2022
(30/11/2022)
סה"כ נכסי הקופות - לפי סוג קופה
(במיליוני ש"ח)
נכון לסוף אוקטובר 2022
תשואה שנתית
סה"כ נכסים
קופ"ג להשקעה- חסכון לילד
קופ"ג להשקעה
מטרה אחרת
מרכזית לפיצויים
קרנות השתלמות
תגמולים ואישית לפיצויים
שנת דיווח
---
648,227
14,480
34,775
946
10,806
303,352
283,869
2022
12.33%
688,304
14,441
34,409
1,043
12,370
321,477
304,565
2021
4.58%
579,438
10,997
20,172
950
12,022
272,631
262,666
2020
11.77%
511,987
---
---
933
13,463
250,174
247,416
2019
התשואה הממוצעת בענף קופות גמל
-6.66%
ב- 12 חודשים האחרונים עמדה עלhttps://stackoverflow.com/questions/74625443
复制相似问题