在python,selenium,Win 7下工作,我想点击sowcomment
按钮后就可以点击位于这个webPage,由wait
处理,然后我想点击showmore Comments
按钮来查看更多评论以便刮掉更多评论。第一个按钮后,我可以提取评论。如何使用硒python3单击一个网页上的第二个按钮?
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,我给出了上面的链接,你可以去。我也尝试过其他选择器,但都是徒劳的。 – Ali
这次我不能看到HTML,因为我不是PC,这就是为什么我要告诉你在这里分享链接HTML .. –