python中的selenium webdriver睡眠错误
对于我用python编写的一个刮取函数收到的这个错误,我有点困惑。我以前调用过该函数,但没有收到此错误python中的selenium webdriver睡眠错误,python,selenium,xpath,webdriver,selenium-chromedriver,Python,Selenium,Xpath,Webdriver,Selenium Chromedriver,对于我用python编写的一个刮取函数收到的这个错误,我有点困惑。我以前调用过该函数,但没有收到此错误 content = [link.get_attribute('textContent') for link in wait(browser, 10).until(EC.presence_of_all_elements_located((By.XPATH, '//ul[@class="twin_set_list"]//a')))] TypeError: sleep() takes exact
content = [link.get_attribute('textContent') for link in wait(browser,
10).until(EC.presence_of_all_elements_located((By.XPATH,
'//ul[@class="twin_set_list"]//a')))]
TypeError: sleep() takes exactly one argument (2 given)
以下是我正在使用的代码:
def ct_content(url):
browser = webdriver.Chrome()
browser.get(url)
content = [link.get_attribute('textContent') for link in wait(browser,
10).until(EC.presence_of_all_elements_located((By.XPATH,
'//ul[@class="twin_set_list"]//a')))]
dates = [link.get_attribute('textContent') for link in wait(browser,
10).until(EC.presence_of_all_elements_located((By.XPATH,
'//p[@class="ellipsis"]//a')))]
if(len(dates)>4):
content.append(dates[3])
else:
content.append("NO_DW")
browser.quit()
return content
在本例中,url为:
任何帮助/见解都将非常有用!谢谢展示一下你的
wait()
的样子你的意思是你想让我打印(wait(browser,10))
不。我是指定义,但我猜它是来自selenium.webdriver.support.ui导入WebDriverWait作为wait,对吗?是的-你把它给了我……这很奇怪。实际上,在wait()
定义中有一个sleep()
——第三个参数poll\u frequency
是一个传递到sleep()
的值,但即使尝试wait(驱动程序=浏览器,超时=10,poll\u frequency=(1,2))
也不会引发类型错误。我也不能用你的代码重现这个问题。您可以尝试显式设置poll\u frequency
值以避免异常