【发布时间】:2016-07-30 10:08:41
【问题描述】:
在 python、selenium、Win 7 中工作,我想点击位于 webPage 上的 sowcomment 按钮,该按钮由 wait 处理,然后我想点击 showmore Comments按钮以查看更多 cmets 以刮取更多 cmets。在第一个按钮之后,我可以提取 cmets。
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import selenium.common.exceptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import selenium.webdriver.support.ui as UI
driver = webdriver.Firefox()
driver.get("http://www.aljazeera.com/news/2016/07/erdogan-west-mind-business-160729205425215.html")
wait = UI.WebDriverWait(driver, 10)
next_page_link = wait.until(
EC.element_to_be_clickable((By.ID, 'showcomment')))
next_page_link.click()
wait = UI.WebDriverWait(driver, 20)
next_page_link2 = wait.until(
EC.element_to_be_clickable((By.LINK_TEXT, 'Show more comments')))
next_page_link2.click()
v = driver.find_elements_by_class_name('gig-comment-body')
print(v)
for h in v:
print(h.text)
但第二个按钮无法点击而给出异常:
selenium.common.exceptions.TimeoutException:
有什么问题?
【问题讨论】:
-
你能在这里分享这个链接的 HTML 吗?还是您尝试过其他定位器?或者尝试使用
By.PARTIAL_LINK_TEXT.. -
@SaurabhGaur 对于 HTML,我在上面提供了链接,您可以访问。我也尝试了其他选择器,但都是徒劳的。
-
这次给定您的链接,我无法看到 HTML,因为我不在 PC 上,所以我告诉您在此处分享该链接 HTML..
-
@SaurabhGaur
http://www.aljazeera.com/news/2016/07/generals-resign-turkey-military-council-160728055057094.html
标签: python-3.x selenium selenium-webdriver web-crawler