【发布时间】:2015-04-13 10:01:47
【问题描述】:
我正在使用 selenium 从网页中收集信息。有两种网页,一种需要按下按钮显示所需信息,另一种直接显示信息。
try:
BrowserObj_dirver.find_element_by_xpath("//li[@id='tab-item-relationships']/a").click()
test=BrowserObj_dirver.find_elements_by_xpath("//div[@class='enum']/a")
for t in test:
if t.text not in sha256:
sql2="insert into sha2 values (%d,'%s')" % (virusId,t.text)
sha256.append(t.text)
cursor.execute(sql2)
db.commit()
virusId=virusId+1
print t.text
except NoSuchElementException:
print "no button"
(and operation for no button page here)
但是遇到NoSuchElementException需要更多的时间,一般是7s -10s。是什么原因?
【问题讨论】:
-
尝试将隐式等待时间设置为您想要的值,例如 BrowserObj_dirver.implicitly_wait(10) # seconds
-
非常感谢。有用。我认为implicitly_wait 仅适用于之前的下一次搜索,但实际上它会影响之后的everyvsearch。谢谢。
-
很高兴听到。将此信息添加为完整回复 - 如果您接受答案,问题将不会保持开放状态。