尝试介于两者之间
wd = webdriver.Firefox()wd.implicitly_wait(3)def get_items(items): print len(items) wd.execute_script("window.scrollTo(0, document.body.scrollHeight);") # len(items) and len(wd.find_elements-by...()) both always seem to return the same number # if I were to start the loop with while True: it would work, but of course... never end sleep(5) #seconds while len(wd.find_elements_by_class_name('stream-item')) > len(items): items = wd.find_elements_by_class_name('stream-item') print items wd.execute_script("window.scrollTo(0, document.body.scrollHeight);") return itemsdef test(): get_page('http://twitter.com/') get_items(wd.find_elements_by_class_name('stream-item'))
注意:硬睡眠只是为了证明它有效。请改用waits包来等待智能状态。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)