首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium TimeoutException:使用selenium的消息

Selenium TimeoutException:使用selenium的消息
EN

Stack Overflow用户
提问于 2022-11-30 09:29:33
回答 1查看 32关注 0票数 0
代码语言:javascript
复制
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

代码语言:javascript
复制
   table 

EN

回答 1

Stack Overflow用户

发布于 2022-11-30 09:50:48

这里有几个问题需要改进:

  1. 您试图使用的Aaaa89455bbfe4387b92529246ea52dc6114类是一个动态值。
  2. 是您单击进入系统的第一个元素,您应该等待元素可点击性,而不仅仅是可见性。这些条件几乎是相似的,但是由于要单击,所以应该检查元素的可点击性。当我们要提取该元素的文本表单时,通常使用可见性。在review=WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='knisa']")))
  3. You可以直接单击WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='knisa']")))返回的web元素对象之前,
  4. 不需要添加time.sleep(2),也不需要将其存储到最初打印的显示“加载”内容的review临时variable.
  5. The表中。因此,为了克服这个问题,我正在等待其中一个列的出现,再添加一些延迟,然后获取整个表文本。

不理想,但以下几点是可行的:

代码语言:javascript
复制
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)

产出如下:

代码语言:javascript
复制
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 חודשים האחרונים עמדה על
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74625443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档