【发布时间】:2014-09-18 14:43:18
【问题描述】:
我正在使用以下代码滚动页面并关注 quora 上的用户(链接到页面:http://www.quora.com/Kevin-Rose/followers),向下滚动后加载了一定数量的用户,我使用下面给出的代码:
# find all the follow buttons that are loaded
button = driver.find_elements_by_xpath("//a[contains(text(), 'Follow')]")
#number of users loaded
no_of_followers = len(button)
#execute the code till all the users are followed
while(no_of_followers > 0):
count = 0
#follow all the users loaded by clicking follow button in a loop
while(count < no_of_followers):
button[count].click()
time.sleep(30)
print count
count = count + 1
#scroll down
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(30)'
#find newly loaded users
button = driver.find_elements_by_xpath("//a[contains(text(), 'Follow')]")
time.sleep(30)
#tracking no of users left unfollowed
no_of_followers = len(button)
我收到以下错误:
StaleElementReferenceException: Message: u'Element is no longer attach to the DOM' ;堆栈跟踪:
编辑1:我尝试使用find_element_by_link _text,但显然该函数的输出对象不是可以迭代的链接列表。
【问题讨论】:
标签: python-2.7 selenium-webdriver web-scraping