我從here爬行文本。我需要反覆點擊「Load More Arguments」來獲取頁面上列出的所有參數。這裏是我的代碼:如何使用硒重複獲取內容<Python>?
try:
while True:
link = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.LINK_TEXT, "Load More Arguments")))
ActionChains(driver).move_to_element(link).perform()
link.click()
time.sleep(3) #wait for the update to occurr so the page loads"new arguments for you"
print(driver.execute_script("return document.documentElement.outerHTML;"))
if not (link):
break
finally:
None
以下是錯誤:
File "debate.py", line 42, in <module>
EC.element_to_be_clickable((By.LINK_TEXT, "Load More Arguments")))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/support/wait.py", line 71, in until
raise TimeoutException(message)
selenium.common.exceptions.TimeoutException: Message:
我得到的頁面上列出的觀點,但我認爲我的代碼是有點怪,特別是在循環。我認爲我需要一些東西來替代「如果不是」,比如「不可點擊」。你能給我一些建議嗎?
謝謝。
謝謝你的解釋。這真的很有幫助。 :) – theteddyboy 2015-02-07 19:41:52