gpt4 book ai didi

python - 具有预期条件的 Selenium : 'str' object is not callable

转载 作者:行者123 更新时间:2023-12-04 12:48:07 26 4
gpt4 key购买 nike

我得到了

Traceback (most recent call last):
File "/Users/xyz/Documents/Projects/apartmentsearch/stanga.py", line 46, in <module>
wait.until(EC.visibility_of_element_located(By.CLASS_NAME('sk-fading-circle spinner-container-3')))
TypeError: 'str' object is not callable

运行这段代码时

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

PHANTOMJS_PATH = './pjs/bin/phantomjs'

browser = webdriver.PhantomJS(PHANTOMJS_PATH)
browser.get('REDACTED')

wait = WebDriverWait(browser, 10)
wait.until(EC.visibility_of_element_located(By.CLASS_NAME('sk-fading-circle spinner-container-3')))
wait.until(EC.invisibility_of_element_located(By.CLASS_NAME('sk-fading-circle spinner-container-3')))

soup = BeautifulSoup(browser.page_source, "html.parser")

print(soup.prettify())

运行 python 2.7。已编辑的网站 URL 但它可以正常工作,我无需等待即可加载页面。

在线代码片段似乎表明像这样的代码应该是可运行的。我错过了什么?我会使用断点来解决问题,但 PyCharm 出于某种原因并没有在我的断点处停止,这也是我想弄清楚的...

最佳答案

您指定的定位器有误。它需要是 (By, selector_string)

的元组(或数组)
wait = WebDriverWait(browser, 10)
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'sk-fading-circle
spinner-container-3')))
wait.until(EC.invisibility_of_element_located((By.CLASS_NAME, 'sk-fading-circle
spinner-container-3')))

而且您似乎正尝试为 CLASS_NAME 使用多个类。我认为那行不通。你应该试试 (By.CSS_SELECTOR, '.sk-fading-circle.spinner-container-3') 而不是

关于python - 具有预期条件的 Selenium : 'str' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42611412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com